Skip to content

Commit

Permalink
rework + uitbreiding (mock) unit test, refactor utility klasse
Browse files Browse the repository at this point in the history
  • Loading branch information
mprins committed Sep 16, 2019
1 parent 447441d commit e95bf11
Show file tree
Hide file tree
Showing 8 changed files with 394 additions and 170 deletions.
2 changes: 1 addition & 1 deletion .mvn/maven.config
Original file line number Diff line number Diff line change
@@ -1 +1 @@
-T1.1C
-T1
12 changes: 6 additions & 6 deletions Gds2Afgifte-AfgifteService-v2-0-soapui-project_20171130.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<con:soapui-project id="595a9503-d6ad-4ae8-9044-44a00670aa61" activeEnvironment="Default" name="Gds2Afgifte_AfgifteService_v2_0" resourceRoot="" soapui-version="5.4.0" abortOnError="false" runType="SEQUENTIAL" xmlns:con="http://eviware.com/soapui/config"><con:settings><con:setting id="com.eviware.soapui.impl.wsdl.actions.iface.tools.soapui.TestRunnerAction@values-local"><![CDATA[<xml-fragment xmlns:con="http://eviware.com/soapui/config">
<con:soapui-project id="595a9503-d6ad-4ae8-9044-44a00670aa61" activeEnvironment="Default" name="Gds2Afgifte_AfgifteService_v2_0" resourceRoot="" soapui-version="5.5.0" abortOnError="false" runType="SEQUENTIAL" xmlns:con="http://eviware.com/soapui/config"><con:settings><con:setting id="com.eviware.soapui.impl.wsdl.actions.iface.tools.soapui.TestRunnerAction@values-local"><![CDATA[<xml-fragment xmlns:con="http://eviware.com/soapui/config">
<con:entry key="Report Format(s)" value=""/>
<con:entry key="Host:Port" value=""/>
<con:entry key="Export JUnit Results" value="false"/>
Expand Down Expand Up @@ -792,9 +792,9 @@
</v20:verzoek>
</v20:BestandenlijstOpvragenRequest>
</soapenv:Body>
</soapenv:Envelope>]]></con:request><con:assertion type="SOAP Response" id="61ec3daa-e149-4d2a-b1c7-13829a60724a"/><con:assertion type="Schema Compliance" id="dcc510da-fb3b-4819-9807-4e508dd15939"><con:configuration/></con:assertion><con:credentials><con:authType>No Authorization</con:authType></con:credentials><con:jmsConfig JMSDeliveryMode="PERSISTENT"/><con:jmsPropertyConfig/><con:wsaConfig mustUnderstand="NONE" version="200508"/><con:wsrmConfig version="1.2"/></con:request></con:config></con:testStep><con:properties/></con:testCase><con:properties/></con:testSuite><con:mockService port="8088" path="/AfgifteService" host="localhost" name="AfgifteService Mock" bindToHostOnly="false" docroot="" id="4e108166-bf40-415b-b6f5-1f747b373af3"><con:settings><con:setting id="com.eviware.soapui.impl.wsdl.mock.WsdlMockService@require-soap-action">false</con:setting></con:settings><con:properties/><con:mockOperation name="BestandenlijstOpvragen" interface="Gds2AfgifteServiceSoapOverHttp" operation="BestandenlijstOpvragen" id="01fc393b-d7b9-459f-b2c4-029bf3c3a6fa"><con:settings/><con:defaultResponse>GeenResponse</con:defaultResponse><con:dispatchStyle>SCRIPT</con:dispatchStyle><con:dispatchPath><![CDATA[def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
</soapenv:Envelope>]]></con:request><con:assertion type="SOAP Response" id="61ec3daa-e149-4d2a-b1c7-13829a60724a"/><con:assertion type="Schema Compliance" id="dcc510da-fb3b-4819-9807-4e508dd15939"><con:configuration/></con:assertion><con:credentials><con:authType>No Authorization</con:authType></con:credentials><con:jmsConfig JMSDeliveryMode="PERSISTENT"/><con:jmsPropertyConfig/><con:wsaConfig mustUnderstand="NONE" version="200508"/><con:wsrmConfig version="1.2"/></con:request></con:config></con:testStep><con:properties/></con:testCase><con:properties/></con:testSuite><con:mockService port="8088" path="/AfgifteService" host="localhost" name="AfgifteService Mock" bindToHostOnly="false" docroot="" id="4e108166-bf40-415b-b6f5-1f747b373af3"><con:settings><con:setting id="com.eviware.soapui.impl.wsdl.mock.WsdlMockService@require-soap-action">false</con:setting><con:setting id="com.eviware.soapui.impl.wsdl.panels.mock.WsdlMockServiceDesktopPanel$LogListModel@maxSize">100</con:setting></con:settings><con:properties/><con:mockOperation name="BestandenlijstOpvragen" interface="Gds2AfgifteServiceSoapOverHttp" operation="BestandenlijstOpvragen" id="01fc393b-d7b9-459f-b2c4-029bf3c3a6fa"><con:settings/><con:defaultResponse>GeenResponse</con:defaultResponse><con:dispatchStyle>SCRIPT</con:dispatchStyle><con:dispatchPath><![CDATA[def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def holder = new com.eviware.soapui.support.XmlHolder(mockRequest.requestContent)
/* beetje dom van kadaster; hardcoded namescapce aliases
/* beetje dom van kadaster; hardcoded namescpace aliases
def contractnummer = String.valueOf(holder.getNodeValue("//v201:contractnummer"))
def artikelnummer= String.valueOf(holder.getNodeValue("//v201:artikelnummer"))
def datumtijdvan= String.valueOf(holder.getNodeValue("//v202:DatumTijdVanaf"))
Expand Down Expand Up @@ -1505,7 +1505,7 @@ else {return "GeenResponse"}]]></con:dispatchPath><con:response name="AlleBestan
<v201:ProcesVerwerkingCode>1</v201:ProcesVerwerkingCode>
<v201:SeverityCode>INFO</v201:SeverityCode>
</v201:ProcesVerwerking>
<v202:klantAfgiftenummerMax>4142</v202:klantAfgiftenummerMax>
<v202:klantAfgiftenummerMax>4140</v202:klantAfgiftenummerMax>
<v202:afgifteAantalInLijst>5</v202:afgifteAantalInLijst>
<v202:BaseURLSet>
<v203:BaseURL type="login">https://service10.kadaster.nl/gds2/download/private</v203:BaseURL>
Expand Down Expand Up @@ -1698,7 +1698,7 @@ else {return "GeenResponse"}]]></con:dispatchPath><con:response name="AlleBestan
<v201:ProcesVerwerkingCode>1</v201:ProcesVerwerkingCode>
<v201:SeverityCode>INFO</v201:SeverityCode>
</v201:ProcesVerwerking>
<v202:klantAfgiftenummerMax>4142</v202:klantAfgiftenummerMax>
<v202:klantAfgiftenummerMax>41420</v202:klantAfgiftenummerMax>
<v202:afgifteAantalInLijst>3</v202:afgifteAantalInLijst>
<v202:BaseURLSet>
<v203:BaseURL type="login">https://service10.kadaster.nl/gds2/download/private</v203:BaseURL>
Expand Down Expand Up @@ -1823,7 +1823,7 @@ else {return "GeenResponse"}]]></con:dispatchPath><con:response name="AlleBestan
<v201:ProcesVerwerkingCode>1</v201:ProcesVerwerkingCode>
<v201:SeverityCode>INFO</v201:SeverityCode>
</v201:ProcesVerwerking>
<v202:klantAfgiftenummerMax>4142</v202:klantAfgiftenummerMax>
<v202:klantAfgiftenummerMax>4143</v202:klantAfgiftenummerMax>
<v202:afgifteAantalInLijst>3</v202:afgifteAantalInLijst>
<v202:BaseURLSet>
<v203:BaseURL type="login">https://service10.kadaster.nl/gds2/download/private</v203:BaseURL>
Expand Down
1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down
131 changes: 129 additions & 2 deletions src/main/java/nl/b3p/gds2/GDS2Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
*/
package nl.b3p.gds2;

import nl.kadaster.schemas.gds2.afgifte_bestandenlijstopvragenresultaat.v20170401.BestandenlijstOpvragenResultaatType;
import nl.kadaster.schemas.gds2.afgifte_bestandenlijstresultaat.afgifte.v20170401.AfgifteType;
import nl.kadaster.schemas.gds2.imgds.baseurl.v20170401.BaseURLType;
import nl.kadaster.schemas.gds2.service.afgifte.v20170401.Gds2AfgifteServiceV20170401;
import nl.kadaster.schemas.gds2.service.afgifte_bestandenlijstopvragen.v20170401.BestandenlijstOpvragenRequest;
import nl.kadaster.schemas.gds2.service.afgifte_bestandenlijstopvragen.v20170401.BestandenlijstOpvragenResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import java.io.ByteArrayInputStream;
import java.io.UnsupportedEncodingException;
import java.security.KeyFactory;
Expand All @@ -14,18 +26,24 @@
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
import java.util.Base64;
import java.util.Date;
import java.util.GregorianCalendar;


/**
*
* @author mprins
*/
public class GDS2Util {

private static final Log LOG = LogFactory.getLog(GDS2Util.class);
private static final String PEM_KEY_START = "-----BEGIN PRIVATE KEY-----";
private static final String PEM_KEY_END = "-----END PRIVATE KEY-----";
private static final String PEM_CERT_START = "-----BEGIN CERTIFICATE-----";
private static final String PEM_CERT_END = "-----END CERTIFICATE-----";

private GDS2Util() {
}

public static Certificate getCertificateFromPEM(String pem) throws CertificateException, UnsupportedEncodingException {
if (!pem.startsWith(PEM_CERT_START)) {
throw new IllegalArgumentException("Certificaat moet beginnen met " + PEM_CERT_START);
Expand Down Expand Up @@ -55,6 +73,115 @@ public static PrivateKey getPrivateKeyFromPEM(String pem) throws NoSuchAlgorithm
return kf.generatePrivate(spec);
}

private GDS2Util() {
/**
* vraagt de bestandenlijst op in maximaal 2 pogingen met 10000 millisec pauze.
*
* @param gds2 afgifte service
* @param request geconfigureerd verzoek
* @return opgevraagde bestanden lijst
* @see #retryBestandenLijstGBOpvragen(Gds2AfgifteServiceV20170401, BestandenlijstOpvragenRequest, int, int)
*/
public static BestandenlijstOpvragenResponse retryBestandenLijstGBOpvragen(Gds2AfgifteServiceV20170401 gds2, BestandenlijstOpvragenRequest request) throws Exception {
return retryBestandenLijstGBOpvragen(gds2, request, 2, 10000);
}

/**
* vraagt de bestandenlijst op.
*
* @param gds2 afgifte service
* @param request geconfigureerd verzoek
* @param retries aantal pogingen om verzoek uit te voeren
* @param retryWait te wachten milliseconden tussen retries, wordt vermenigvuldigd met retry poging (dus periode steeds langer)
* @return opgevraagde bestanden lijst
*/
public static BestandenlijstOpvragenResponse retryBestandenLijstGBOpvragen(Gds2AfgifteServiceV20170401 gds2, BestandenlijstOpvragenRequest request, int retries, int retryWait) throws Exception {
int attempt = 0;
while (true) {
try {
return gds2.bestandenlijstOpvragen(request);
} catch (Exception e) {
attempt++;
if (attempt == retries) {
LOG.error("Fout bij laatste poging ophalen bestandenlijst: " + e.getClass().getName() + ": " + e.getMessage());
throw e;
} else {
LOG.warn("Fout bij poging " + attempt + " om bestandenlijst op te halen: " + e.getClass().getName() + ": " + e.getMessage());
Thread.sleep(retryWait * attempt);
LOG.info("Uitvoeren poging " + (attempt + 1) + " om bestandenlijst op te halen...");
}
}
}
}

/**
* bepaal de "certificaat" url, nodig voor BRK download met PKI.
*
* @param antwoord de url
* @return type of {@code null}
*/
public static BaseURLType getCertificaatBaseURL(BestandenlijstOpvragenResultaatType antwoord) {
for (BaseURLType type : antwoord.getBaseURLSet().getBaseURL()) {
if (type.getType().equalsIgnoreCase("certificaat")) {
return type;
}
}
return null;
}

/**
* bepaal de "anoniem" url, nodig voor BAG download zonder PKI.
*
* @param antwoord de url
* @return type of {@code null}
*/
public static BaseURLType getAnoniemBaseURL(BestandenlijstOpvragenResultaatType antwoord) {
for (BaseURLType type : antwoord.getBaseURLSet().getBaseURL()) {
if (type.getType().equalsIgnoreCase("anoniem")) {
return type;
}
}
return null;
}

/**
* bepaal de afgifte url.
*
* @param afgifte de afgifte
* @param type de base url
* @return de afgifte url
*/
public static String getAfgifteURL(AfgifteType afgifte, BaseURLType type) {
return type.getValue() + "/" + afgifte.getBestand().getBestandsnaam();
}

/**
* maakt een datum die te gebruiken is in een "van" of "tot" criterium, houdt rekening met de juiste maand.
*
* @param year jaartal (4 cijfers, > 2000)
* @param month maand (waarde van 0 t/m 12)
* @param day dag van de maand
* @return xml datum
* @throws DatatypeConfigurationException If the implementation of DatatypeFactory is not available or cannot be instantiated.
*/
public static XMLGregorianCalendar getGregorianCalendar(int year, int month, int day) throws DatatypeConfigurationException {
return DatatypeFactory.newInstance().newXMLGregorianCalendar(
new GregorianCalendar(
year,
month - 1 /* GregorianCalendar heeft 0-based month */,
day)
);
}

/**
* maakt een datum die te gebruiken is in een "van" of "tot" criterium.
*
* @param date datum
* @return xml datum
* @throws DatatypeConfigurationException If the implementation of DatatypeFactory is not available or cannot be instantiated.
*/
public static XMLGregorianCalendar getGregorianCalendar(Date date) throws DatatypeConfigurationException {
final GregorianCalendar cal = new GregorianCalendar();
cal.setTime(date);
return DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);
}
}
Loading

0 comments on commit e95bf11

Please sign in to comment.