|
| 1 | +package de.rwth.idsg.steve; |
| 2 | + |
| 3 | +import lombok.extern.slf4j.Slf4j; |
| 4 | +import ocpp.cs._2010._08.AuthorizationStatus; |
| 5 | +import ocpp.cs._2010._08.AuthorizeRequest; |
| 6 | +import ocpp.cs._2010._08.AuthorizeResponse; |
| 7 | +import ocpp.cs._2010._08.BootNotificationRequest; |
| 8 | +import ocpp.cs._2010._08.BootNotificationResponse; |
| 9 | +import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; |
| 10 | +import org.apache.cxf.ws.addressing.WSAddressingFeature; |
| 11 | +import org.joda.time.DateTime; |
| 12 | +import org.joda.time.DateTimeZone; |
| 13 | +import org.junit.Assert; |
| 14 | +import org.junit.Ignore; |
| 15 | +import org.junit.Test; |
| 16 | + |
| 17 | +import javax.xml.ws.soap.SOAPBinding; |
| 18 | +import java.util.TimeZone; |
| 19 | +import java.util.UUID; |
| 20 | + |
| 21 | +import static de.rwth.idsg.steve.SteveConfiguration.CONFIG; |
| 22 | + |
| 23 | +/** |
| 24 | + * @author Sevket Goekay <goekay@dbis.rwth-aachen.de> |
| 25 | + * @since 10.03.2018 |
| 26 | + */ |
| 27 | +@Ignore |
| 28 | +@Slf4j |
| 29 | +public class ApplicationTest { |
| 30 | + |
| 31 | + private static final String path = getPath(); |
| 32 | + |
| 33 | + /** |
| 34 | + * Tests that the SOAP code paths are working. |
| 35 | + */ |
| 36 | + @Test |
| 37 | + public void testSoapPipeline() throws Exception { |
| 38 | + startApp(); |
| 39 | + |
| 40 | + BootNotificationResponse boot12 = getForOcpp12().bootNotification( |
| 41 | + new BootNotificationRequest() |
| 42 | + .withChargePointVendor(getRandomString()) |
| 43 | + .withChargePointModel(getRandomString()), |
| 44 | + getRandomString()); |
| 45 | + Assert.assertNotNull(boot12); |
| 46 | + Assert.assertEquals(ocpp.cs._2010._08.RegistrationStatus.REJECTED, boot12.getStatus()); |
| 47 | + |
| 48 | + ocpp.cs._2012._06.BootNotificationResponse boot15 = getForOcpp15().bootNotification( |
| 49 | + new ocpp.cs._2012._06.BootNotificationRequest() |
| 50 | + .withChargePointVendor(getRandomString()) |
| 51 | + .withChargePointModel(getRandomString()), |
| 52 | + getRandomString()); |
| 53 | + Assert.assertNotNull(boot15); |
| 54 | + Assert.assertEquals(ocpp.cs._2012._06.RegistrationStatus.REJECTED, boot15.getStatus()); |
| 55 | + |
| 56 | + AuthorizeResponse auth12 = getForOcpp12().authorize( |
| 57 | + new AuthorizeRequest() |
| 58 | + .withIdTag(getRandomString()), |
| 59 | + getRandomString()); |
| 60 | + Assert.assertNotNull(auth12); |
| 61 | + Assert.assertEquals(AuthorizationStatus.INVALID, auth12.getIdTagInfo().getStatus()); |
| 62 | + |
| 63 | + ocpp.cs._2012._06.AuthorizeResponse auth15 = getForOcpp15().authorize( |
| 64 | + new ocpp.cs._2012._06.AuthorizeRequest() |
| 65 | + .withIdTag(getRandomString()), |
| 66 | + getRandomString()); |
| 67 | + Assert.assertNotNull(auth15); |
| 68 | + Assert.assertEquals(ocpp.cs._2012._06.AuthorizationStatus.INVALID, auth15.getIdTagInfo().getStatus()); |
| 69 | + } |
| 70 | + |
| 71 | + private JettyServer startApp() throws Exception { |
| 72 | + // For Hibernate validator |
| 73 | + System.setProperty("org.jboss.logging.provider", "slf4j"); |
| 74 | + |
| 75 | + TimeZone.setDefault(TimeZone.getTimeZone("UTC")); |
| 76 | + DateTimeZone.setDefault(DateTimeZone.UTC); |
| 77 | + log.info("Date/time zone of the application is set to UTC. Current date/time: {}", DateTime.now()); |
| 78 | + |
| 79 | + SteveConfiguration sc = CONFIG; |
| 80 | + |
| 81 | + log.info("Loaded the properties. Starting with the '{}' profile", sc.getProfile()); |
| 82 | + |
| 83 | + JettyServer jettyServer = new JettyServer(); |
| 84 | + jettyServer.prepare(); |
| 85 | + jettyServer.start(); |
| 86 | + return jettyServer; |
| 87 | + } |
| 88 | + |
| 89 | + private static String getRandomString() { |
| 90 | + return UUID.randomUUID().toString(); |
| 91 | + } |
| 92 | + |
| 93 | + private static String getPath() { |
| 94 | + if (CONFIG.getJetty().isHttpEnabled()) { |
| 95 | + return "http://" |
| 96 | + + CONFIG.getJetty().getServerHost() + ":" |
| 97 | + + CONFIG.getJetty().getHttpPort() |
| 98 | + + CONFIG.getContextPath() + "/services" |
| 99 | + + CONFIG.getRouterEndpointPath(); |
| 100 | + } else if (CONFIG.getJetty().isHttpsEnabled()) { |
| 101 | + return "https://" |
| 102 | + + CONFIG.getJetty().getServerHost() + ":" |
| 103 | + + CONFIG.getJetty().getHttpsPort() |
| 104 | + + CONFIG.getContextPath() + "/services" |
| 105 | + + CONFIG.getRouterEndpointPath(); |
| 106 | + } else { |
| 107 | + throw new RuntimeException(); |
| 108 | + } |
| 109 | + } |
| 110 | + |
| 111 | + private static ocpp.cs._2012._06.CentralSystemService getForOcpp15() { |
| 112 | + JaxWsProxyFactoryBean f = getBean(path); |
| 113 | + f.setServiceClass(ocpp.cs._2012._06.CentralSystemService.class); |
| 114 | + return (ocpp.cs._2012._06.CentralSystemService) f.create(); |
| 115 | + } |
| 116 | + |
| 117 | + private static ocpp.cs._2010._08.CentralSystemService getForOcpp12() { |
| 118 | + JaxWsProxyFactoryBean f = getBean(path); |
| 119 | + f.setServiceClass(ocpp.cs._2010._08.CentralSystemService.class); |
| 120 | + return (ocpp.cs._2010._08.CentralSystemService) f.create(); |
| 121 | + } |
| 122 | + |
| 123 | + private static JaxWsProxyFactoryBean getBean(String endpointAddress) { |
| 124 | + JaxWsProxyFactoryBean f = new JaxWsProxyFactoryBean(); |
| 125 | + f.setBindingId(SOAPBinding.SOAP12HTTP_BINDING); |
| 126 | + f.getFeatures().add(new WSAddressingFeature()); |
| 127 | + f.setAddress(endpointAddress); |
| 128 | + return f; |
| 129 | + } |
| 130 | +} |
0 commit comments