PropertyBasedArtifactUrlHandler implements ArtifactUrlHandler { @Override public List<ArtifactUrl> getUrls(final URLPlaceholder placeholder, final ApiType api) { return getUrls(placeholder, api, null); } PropertyBasedArtifactUrlHandler(final ArtifactUrlHandlerProperties urlHandlerProperties); @Override List<ArtifactUrl> getUrls(final URLPlaceholder placeholder, final ApiType api); @Override List<ArtifactUrl> getUrls(final URLPlaceholder placeholder, final ApiType api, final URI requestUri);  }
@Test @Description("Tests the generation of http download url.") public void urlGenerationWithDefaultConfiguration() { properties.getProtocols().put("download-http", new UrlProtocol()); final List<ArtifactUrl> ddiUrls = urlHandlerUnderTest.getUrls(placeholder, ApiType.DDI); assertThat(ddiUrls).containsExactly( new ArtifactUrl("http".toUpperCase(), "download-http", HTTP_LOCALHOST + TENANT + "/controller/v1/" + CONTROLLER_ID + "/softwaremodules/" + SOFTWAREMODULEID + "/artifacts/" + FILENAME_ENCODE)); final List<ArtifactUrl> dmfUrls = urlHandlerUnderTest.getUrls(placeholder, ApiType.DMF); assertThat(ddiUrls).isEqualTo(dmfUrls); }
@Test @Description("Tests the generation of custom download url with a CoAP example that supports DMF only.") public void urlGenerationWithCustomConfiguration() { final UrlProtocol proto = new UrlProtocol(); proto.setIp("127.0.0.1"); proto.setPort(5683); proto.setProtocol(TEST_PROTO); proto.setRel(TEST_REL); proto.setSupports(Arrays.asList(ApiType.DMF)); proto.setRef("{protocol}: properties.getProtocols().put(TEST_PROTO, proto); List<ArtifactUrl> urls = urlHandlerUnderTest.getUrls(placeholder, ApiType.DDI); assertThat(urls).isEmpty(); urls = urlHandlerUnderTest.getUrls(placeholder, ApiType.DMF); assertThat(urls).containsExactly(new ArtifactUrl(TEST_PROTO.toUpperCase(), TEST_REL, "coap: }
@Test @Description("Tests the generation of custom download url using Base62 references with a CoAP example that supports DMF only.") public void urlGenerationWithCustomShortConfiguration() { final UrlProtocol proto = new UrlProtocol(); proto.setIp("127.0.0.1"); proto.setPort(5683); proto.setProtocol(TEST_PROTO); proto.setRel(TEST_REL); proto.setSupports(Arrays.asList(ApiType.DMF)); proto.setRef("{protocol}: properties.getProtocols().put("ftp", proto); List<ArtifactUrl> urls = urlHandlerUnderTest.getUrls(placeholder, ApiType.DDI); assertThat(urls).isEmpty(); urls = urlHandlerUnderTest.getUrls(placeholder, ApiType.DMF); assertThat(urls).containsExactly(new ArtifactUrl(TEST_PROTO.toUpperCase(), TEST_REL, TEST_PROTO + ": }
@Test @Description("Verfies that the full qualified host of the statically defined hostname is replaced with the host of the request.") public void urlGenerationWithHostFromRequest() throws URISyntaxException { final String testHost = "ddi.host.com"; final UrlProtocol proto = new UrlProtocol(); proto.setIp("127.0.0.1"); proto.setPort(5683); proto.setProtocol(TEST_PROTO); proto.setRel(TEST_REL); proto.setSupports(Arrays.asList(ApiType.DDI)); proto.setRef("{protocol}: properties.getProtocols().put("ftp", proto); final List<ArtifactUrl> urls = urlHandlerUnderTest.getUrls(placeholder, ApiType.DDI, new URI("https: assertThat(urls).containsExactly(new ArtifactUrl(TEST_PROTO.toUpperCase(), TEST_REL, TEST_PROTO + ": + testHost + ":5683/fws/" + TENANT + "/" + TARGETID_BASE62 + "/" + ARTIFACTID_BASE62)); }
@Test @Description("Verfies that the port of the statically defined hostname is replaced with the port of the request.") public void urlGenerationWithPortFromRequest() throws URISyntaxException { final UrlProtocol proto = new UrlProtocol(); proto.setRef( "{protocol}: properties.getProtocols().put("download-http", proto); final List<ArtifactUrl> ddiUrls = urlHandlerUnderTest.getUrls(placeholder, ApiType.DDI, new URI("http: assertThat(ddiUrls).containsExactly(new ArtifactUrl("http".toUpperCase(), "download-http", "http: + SOFTWAREMODULEID + "/artifacts/" + FILENAME_ENCODE)); final List<ArtifactUrl> dmfUrls = urlHandlerUnderTest.getUrls(placeholder, ApiType.DMF); assertThat(dmfUrls).containsExactly(new ArtifactUrl("http".toUpperCase(), "download-http", "http: + SOFTWAREMODULEID + "/artifacts/" + FILENAME_ENCODE)); }
@Test @Description("Verfies that the domain of the statically defined hostname is replaced with the domain of the request.") public void urlGenerationWithDomainFromRequest() throws URISyntaxException { final UrlProtocol proto = new UrlProtocol(); proto.setHostname("host.bumlux.net"); proto.setRef( "{protocol}: properties.getProtocols().put("download-http", proto); final List<ArtifactUrl> ddiUrls = urlHandlerUnderTest.getUrls(placeholder, ApiType.DDI, new URI("http: assertThat(ddiUrls).containsExactly( new ArtifactUrl("http".toUpperCase(), "download-http", "http: + CONTROLLER_ID + "/softwaremodules/" + SOFTWAREMODULEID + "/artifacts/" + FILENAME_ENCODE)); final List<ArtifactUrl> dmfUrls = urlHandlerUnderTest.getUrls(placeholder, ApiType.DMF); assertThat(dmfUrls).containsExactly(new ArtifactUrl("http".toUpperCase(), "download-http", "http: + SOFTWAREMODULEID + "/artifacts/" + FILENAME_ENCODE)); }