Skip to content

Commit 2fa10f7

Browse files
committed
Added some functional tests.
1 parent c74fe89 commit 2fa10f7

File tree

4 files changed

+56
-18
lines changed

4 files changed

+56
-18
lines changed

src/test/functional/java/org/nameapi/client/services/development/exceptionthrower/ExceptionThrowerCommandTest.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.testng.annotations.Test;
1313

1414
import static org.testng.Assert.assertEquals;
15+
import static org.testng.Assert.assertFalse;
1516
import static org.testng.Assert.fail;
1617

1718
/**
@@ -31,15 +32,27 @@ public void testCall1() throws Exception {
3132
}
3233
}
3334

34-
@Test(expectedExceptions = InternalServerErrorServiceException.class)
35+
@Test
3536
public void testCall2() throws Exception {
36-
execute(ExceptionType.InternalServerError);
37+
try {
38+
execute(ExceptionType.InternalServerError);
39+
fail("Expected exception!");
40+
} catch (InternalServerErrorServiceException e) {
41+
assertEquals(e.getFaultInfo().getBlame(), Blame.SERVER);
42+
assertFalse(e.getFaultInfo().getRetrySameLocation().isPresent());
43+
}
3744
}
3845

3946

40-
@Test(expectedExceptions = AccessDeniedServiceException.class)
47+
@Test
4148
public void testCall3() throws Exception {
42-
execute(ExceptionType.AccessDeniedNoSuchAccount);
49+
try {
50+
execute(ExceptionType.AccessDeniedNoSuchAccount);
51+
fail("Expected exception!");
52+
} catch (AccessDeniedServiceException e) {
53+
assertEquals(e.getFaultInfo().getBlame(), Blame.CLIENT);
54+
assertEquals(e.getFaultInfo().getRetrySameLocation().get().getRetryType(), RetryType.NO);
55+
}
4356
}
4457

4558
// @Test(expectedExceptions = AccessDeniedServiceException.class)

src/test/functional/java/org/nameapi/client/services/email/disposableemailaddressdetector/DisposableEmailAddressDetectorCommandTest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,16 @@ public class DisposableEmailAddressDetectorCommandTest {
1717

1818

1919
@Test
20-
public void testCall() throws Exception {
20+
public void yes_1() throws Exception {
2121
DisposableEmailAddressDetectorCommand command = new DisposableEmailAddressDetectorCommand();
2222
Mode mode = FunctionalTestsNameApiModeFactory.functionalTest();
2323
assertEquals(executor.execute(command, mode, "[email protected]").get().getDisposable(), Maybe.YES);
2424
}
25+
26+
@Test
27+
public void no_1() throws Exception {
28+
DisposableEmailAddressDetectorCommand command = new DisposableEmailAddressDetectorCommand();
29+
Mode mode = FunctionalTestsNameApiModeFactory.functionalTest();
30+
assertEquals(executor.execute(command, mode, "[email protected]").get().getDisposable(), Maybe.NO);
31+
}
2532
}

src/test/functional/java/org/nameapi/client/services/genderizer/persongenderizer/PersonGenderizerCommandTest.java

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
import org.nameapi.ontology5.input.entities.person.NaturalInputPersonBuilder;
1313
import org.nameapi.ontology5.input.entities.person.age.AgeInfoFactory;
1414
import org.nameapi.ontology5.input.entities.person.gender.ComputedPersonGender;
15+
import org.nameapi.ontology5.input.entities.person.gender.StoragePersonGender;
1516
import org.nameapi.ontology5.services.genderizer.GenderizerResult;
1617
import org.testng.annotations.Test;
1718

1819
import static org.testng.Assert.assertEquals;
20+
import static org.testng.Assert.fail;
1921

2022
/**
2123
*/
@@ -75,16 +77,21 @@ public void testCall3() throws Exception {
7577
assertEquals(result.getGender(), ComputedPersonGender.MALE);
7678
}
7779

78-
// /**
79-
// * Passing the gender is invalid because if it's already known it can only be validated (use another service).
80-
// */
81-
// @Test(expectedExceptions = InvalidInputServiceException.class)
82-
// public void testCall_ex() throws Exception {
83-
// PersonGenderizerCommand command = new PersonGenderizerCommand();
84-
// Mode mode = FunctionalTestsNameApiModeFactory.functionalTest();
85-
// NaturalInputPerson person = new NaturalInputPersonBuilder().name(makeName("John", "Doe"))
86-
// .gender(StoragePersonGender.MALE)
87-
// .build();
88-
// executor.execute(command, mode, person);
89-
// }
80+
/**
81+
* Passing the gender is invalid because if it's already known it can only be validated (use another service).
82+
*/
83+
@Test
84+
public void testCall_ex() throws Exception {
85+
PersonGenderizerCommand command = new PersonGenderizerCommand();
86+
Mode mode = FunctionalTestsNameApiModeFactory.functionalTest();
87+
NaturalInputPerson person = new NaturalInputPersonBuilder().name(makeName("John", "Doe"))
88+
.gender(StoragePersonGender.MALE)
89+
.build();
90+
try {
91+
executor.execute(command, mode, person);
92+
fail("Expected to get an exception!");
93+
} catch (Exception e) {
94+
//currently InternalServerErrorServiceException, something like InvalidInputServiceException would be better suited.
95+
}
96+
}
9097
}

src/test/functional/java/org/nameapi/client/services/matcher/personmatcher/PersonMatcherCommandTest.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public void test_equal() throws Exception {
3131
}
3232

3333
@Test
34-
public void test_matching() throws Exception {
34+
public void test_matching_1() throws Exception {
3535
PersonMatcherCommand command = new PersonMatcherCommand();
3636
Mode mode = FunctionalTestsNameApiModeFactory.functionalTest();
3737
NaturalInputPerson person1 = new NaturalInputPersonBuilder().name(makeName("Petra Müller")).build();
@@ -41,4 +41,15 @@ public void test_matching() throws Exception {
4141
assertEquals(result.getMatchType(), PersonMatchType.MATCHING);
4242
}
4343

44+
@Test
45+
public void test_matching_2() throws Exception {
46+
PersonMatcherCommand command = new PersonMatcherCommand();
47+
Mode mode = FunctionalTestsNameApiModeFactory.functionalTest();
48+
NaturalInputPerson person1 = new NaturalInputPersonBuilder().name(makeName("Petra K. Müller")).build();
49+
NaturalInputPerson person2 = new NaturalInputPersonBuilder().name(makeName("Petra Mueller-Meyer")).build();
50+
PersonMatcherArgument argument = new PersonMatcherArgument(person1, person2);
51+
PersonMatcherResult result = executor.execute(command, mode, argument).get();
52+
assertEquals(result.getMatchType(), PersonMatchType.MATCHING);
53+
}
54+
4455
}

0 commit comments

Comments
 (0)