Skip to content

Commit a7c1bf3

Browse files
committed
Parser tests working.
1 parent 89074e7 commit a7c1bf3

File tree

6 files changed

+79
-29
lines changed

6 files changed

+79
-29
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,43 @@
11
package org.nameapi.client.services.parser.personnameparser;
22

3+
import com.google.common.base.Optional;
4+
import com.optimaize.command4j.ExecutionContext;
5+
import org.jetbrains.annotations.NotNull;
6+
import org.nameapi.client.services.NameApiBaseCommand;
7+
import org.nameapi.client.services.genderizer.persongenderizer.*;
8+
import org.nameapi.ontology5.input.entities.person.InputPerson;
9+
import org.nameapi.ontology5.services.genderizer.GenderizerResult;
10+
import org.nameapi.ontology5.services.parser.personnameparser.PersonNameParserResult;
11+
12+
import java.util.concurrent.Callable;
13+
314
/**
415
* Parses the name fields of a person's name.
516
*/
617
public class PersonNameParserCommand
7-
// extends NameApiBaseCommand<SoapPersonNameParser, InputPerson, PersonNameParserResult>
18+
extends NameApiBaseCommand<RestPort, InputPerson, PersonNameParserResult>
819
{
920

10-
// private static final String servicePath = "/parser/personnameparser";
11-
//
12-
// public PersonNameParserCommand() {
13-
// super(SoapPersonNameParser.class);
14-
// }
15-
//
16-
// @Override @NotNull
17-
// public PersonNameParserResult call(@NotNull Optional<InputPerson> arg, @NotNull ExecutionContext ec) throws Exception {
18-
// SoapPersonNameParserResult result = getPort(ec).parse(getContext(ec), Conversions.convert(arg.get()));
19-
// return ParserConversions.convertResult(result);
20-
// }
21-
//
22-
//
23-
// @NotNull @Override
24-
// protected Callable<SoapPersonNameParser> createPort(@NotNull final ExecutionContext ec) {
25-
// return new Callable<SoapPersonNameParser>() {
26-
// @Override
27-
// public SoapPersonNameParser call() throws Exception {
28-
// URL url = makeUrl(ec, servicePath);
29-
// return new SoapPersonNameParserService(url).getSoapPersonNameParserPort();
30-
// }
31-
// };
32-
// }
21+
22+
private static final String SERVICE_PATH = "/parser/personnameparser";
23+
24+
public PersonNameParserCommand() {
25+
super(RestPort.class);
26+
}
27+
28+
@Override
29+
public PersonNameParserResult call(@NotNull Optional<InputPerson> arg, @NotNull ExecutionContext ec) throws Exception {
30+
return getPort(ec).call(getApiKey(ec), getContext(ec), arg.get());
31+
}
32+
33+
@NotNull @Override
34+
protected Callable<RestPort> createPort(@NotNull final ExecutionContext ec) {
35+
return new Callable<RestPort>() {
36+
@Override
37+
public RestPort call() throws Exception {
38+
return new RestPort(makeClient(ec), SERVICE_PATH);
39+
}
40+
};
41+
}
3342

3443
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package org.nameapi.client.services.parser.personnameparser;
2+
3+
import com.optimaize.anythingworks.client.rest.http.HeaderParams;
4+
import com.optimaize.anythingworks.client.rest.http.QueryParams;
5+
import com.optimaize.anythingworks.client.rest.http.RestHttpClient;
6+
import com.optimaize.anythingworks.client.rest.http.RestHttpClientResponse;
7+
import com.optimaize.anythingworks.common.rest.TypeRef;
8+
import org.nameapi.client.services.RestServicePort;
9+
import org.nameapi.ontology5.input.context.Context;
10+
import org.nameapi.ontology5.input.entities.person.InputPerson;
11+
import org.nameapi.ontology5.services.InputWithPerson;
12+
import org.nameapi.ontology5.services.genderizer.GenderizerResult;
13+
import org.nameapi.ontology5.services.parser.personnameparser.PersonNameParserResult;
14+
15+
/**
16+
*
17+
*/
18+
class RestPort extends RestServicePort {
19+
20+
private static final TypeRef returnType = new TypeRef<PersonNameParserResult>() {};
21+
22+
public RestPort(RestHttpClient restApiClient, String servicePath) {
23+
super(restApiClient, servicePath);
24+
}
25+
26+
public PersonNameParserResult call(String apiKey, Context context, InputPerson inputPerson) {
27+
QueryParams queryParams = QueryParams.create();
28+
queryParams.add("apiKey", apiKey);
29+
30+
RestHttpClientResponse<PersonNameParserResult> response = restApiClient.invokeBody(
31+
servicePath, "POST",
32+
queryParams, HeaderParams.none(),
33+
new InputWithPerson(context, inputPerson),
34+
returnType
35+
);
36+
return response.getResult().get();
37+
}
38+
39+
}

src/test/functional/java/org/nameapi/client/services/parser/personnameparser/PersonNameParserCommandTest.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import org.nameapi.ontology5.input.entities.person.NaturalInputPersonBuilder;
1010
import org.nameapi.ontology5.output.entities.person.name.OutputPersonName;
1111
import org.nameapi.ontology5.output.entities.person.name.TermType;
12+
import org.nameapi.ontology5.services.parser.personnameparser.ParsedPerson;
13+
import org.nameapi.ontology5.services.parser.personnameparser.PersonNameParserResult;
1214
import org.testng.annotations.Test;
1315

1416
import static org.testng.Assert.assertEquals;
@@ -24,11 +26,11 @@ public void testCall() throws Exception {
2426
PersonNameParserCommand command = new PersonNameParserCommand();
2527
Mode mode = FunctionalTestsNameApiModeFactory.functionalTest();
2628
NaturalInputPerson person = new NaturalInputPersonBuilder().name(makeName("Petra Müller")).build();
27-
// PersonNameParserResult result = executor.execute(command, mode, person).get();
28-
// ParsedPerson parsedPerson = result.getBestMatch().getParsedPerson();
29-
// OutputPersonName firstName = parsedPerson.getNames().get(0);
30-
// assertEquals("Petra", firstName.getFirst(TermType.GIVENNAME).get().getString());
31-
// assertEquals("Müller", firstName.getFirst(TermType.SURNAME).get().getString());
29+
PersonNameParserResult result = executor.execute(command, mode, person).get();
30+
ParsedPerson parsedPerson = result.getBestMatch().getParsedPerson();
31+
OutputPersonName firstName = parsedPerson.getNames().get(0);
32+
assertEquals("Petra", firstName.getFirst(TermType.GIVENNAME).get().getString());
33+
assertEquals("Müller", firstName.getFirst(TermType.SURNAME).get().getString());
3234
}
3335

3436
}

0 commit comments

Comments
 (0)