diff --git a/micro-application-register/src/main/java/com/aol/micro/server/application/registry/Health.java b/micro-application-register/src/main/java/com/aol/micro/server/application/registry/Health.java deleted file mode 100644 index 5652579d7..000000000 --- a/micro-application-register/src/main/java/com/aol/micro/server/application/registry/Health.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.aol.micro.server.application.registry; - -public enum Health { - - OK, ERROR -} diff --git a/micro-application-register/src/main/java/com/aol/micro/server/application/registry/Job.java b/micro-application-register/src/main/java/com/aol/micro/server/application/registry/Job.java deleted file mode 100644 index 0fe500513..000000000 --- a/micro-application-register/src/main/java/com/aol/micro/server/application/registry/Job.java +++ /dev/null @@ -1,80 +0,0 @@ -package com.aol.micro.server.application.registry; - -import java.util.Date; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import javax.annotation.PostConstruct; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Component; - -import com.aol.micro.server.rest.client.nio.AsyncRestClient; -import com.aol.micro.server.rest.jackson.JacksonUtil; - -@Component -public class Job { - - private final Logger logger = LoggerFactory.getLogger(getClass()); - private final AsyncRestClient rest = new AsyncRestClient( - 100, 2000); - private final String apiUrl; - private final ApplicationRegisterImpl app; - private final String uuid = UUID.randomUUID() - .toString(); - private final String resourcePath; - private final RegistryHealthChecker checker; - private final RegistryStatsChecker statsChecker; - - @Autowired - public Job(@Value("${service.registry.url:#{null}}") String apiUrl, ApplicationRegisterImpl app, - @Value("${resource.path:/service-registry/register}") String resourcePath, RegistryHealthChecker checker, - RegistryStatsChecker statsChecker) { - - this.apiUrl = apiUrl; - this.app = app; - this.resourcePath = resourcePath; - this.checker = checker; - this.statsChecker = statsChecker; - - } - - @PostConstruct - @Scheduled(fixedDelayString = "${service.registry.delay:1000}") - public synchronized void schedule() { - try { - if (app.getApplication() != null && apiUrl != null) - app.getApplication() - .forEach(moduleEntry -> sendPing(moduleEntry)); - } catch (Exception e) { - logger.error("Failed to register services due to exception {}", e.getMessage(), e); - } - } - - private void sendPing(RegisterEntry moduleEntry) { - final RegisterEntry entry = moduleEntry.withTime(new Date()) - .withUuid(uuid) - .withHealth(checker.isOk() ? Health.OK : Health.ERROR) - .withStats(nonEmptyOrNull(statsChecker.stats())); - try { - - logger.debug("Posting {} to " + apiUrl + resourcePath, JacksonUtil.serializeToJson(entry)); - rest.post(apiUrl + resourcePath, JacksonUtil.serializeToJson(entry)) - .join(); - } catch (Exception e) { - logger.warn("Failed posting {} to {}" + resourcePath, JacksonUtil.serializeToJson(entry), apiUrl); - - } - } - - private List>> nonEmptyOrNull(List>> stats) { - if (stats == null || stats.isEmpty()) - return null; - return stats; - } -} diff --git a/micro-application-register/src/main/java/com/aol/micro/server/application/registry/plugin/ApplicationRegistryPlugin.java b/micro-application-register/src/main/java/com/aol/micro/server/application/registry/plugin/ApplicationRegistryPlugin.java deleted file mode 100644 index 787b9e972..000000000 --- a/micro-application-register/src/main/java/com/aol/micro/server/application/registry/plugin/ApplicationRegistryPlugin.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.aol.micro.server.application.registry.plugin; - -import com.aol.micro.server.Plugin; -import com.aol.micro.server.application.registry.ApplicationRegisterImpl; -import com.aol.micro.server.application.registry.Cleaner; -import com.aol.micro.server.application.registry.Finder; -import com.aol.micro.server.application.registry.RegistryHealthChecker; -import com.aol.micro.server.application.registry.Job; -import com.aol.micro.server.application.registry.Register; -import com.aol.micro.server.application.registry.RegisterConfig; -import com.aol.micro.server.application.registry.ServiceRegistryResource; -import com.aol.micro.server.application.registry.RegistryStatsChecker; -import cyclops.collections.immutable.PersistentSetX; -import cyclops.collections.mutable.SetX; - -import java.util.Set; - -public class ApplicationRegistryPlugin implements Plugin { - - @Override - public Set springClasses() { - return SetX.of(ApplicationRegisterImpl.class, Cleaner.class, Register.class, ServiceRegistryResource.class, - RegisterConfig.class, Job.class, Finder.class, RegistryHealthChecker.class, RegistryStatsChecker.class); - } - -} diff --git a/micro-application-register/src/main/java/com/aol/micro/server/application/registry/Application.java b/micro-application-register/src/main/java/com/oath/micro/server/application/registry/Application.java similarity index 85% rename from micro-application-register/src/main/java/com/aol/micro/server/application/registry/Application.java rename to micro-application-register/src/main/java/com/oath/micro/server/application/registry/Application.java index c03652275..8a9f568fc 100644 --- a/micro-application-register/src/main/java/com/aol/micro/server/application/registry/Application.java +++ b/micro-application-register/src/main/java/com/oath/micro/server/application/registry/Application.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.application.registry; +package com.oath.micro.server.application.registry; import java.util.Iterator; import java.util.List; @@ -9,7 +9,7 @@ import lombok.experimental.FieldDefaults; -import com.aol.micro.server.rest.jackson.JacksonUtil; +import com.oath.micro.server.rest.jackson.JacksonUtil; @FieldDefaults(makeFinal=true, level=AccessLevel.PRIVATE) public class Application implements Iterable{ diff --git a/micro-application-register/src/main/java/com/aol/micro/server/application/registry/ApplicationRegisterImpl.java b/micro-application-register/src/main/java/com/oath/micro/server/application/registry/ApplicationRegisterImpl.java similarity index 95% rename from micro-application-register/src/main/java/com/aol/micro/server/application/registry/ApplicationRegisterImpl.java rename to micro-application-register/src/main/java/com/oath/micro/server/application/registry/ApplicationRegisterImpl.java index 5c17237c8..54f89d2ae 100644 --- a/micro-application-register/src/main/java/com/aol/micro/server/application/registry/ApplicationRegisterImpl.java +++ b/micro-application-register/src/main/java/com/oath/micro/server/application/registry/ApplicationRegisterImpl.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.application.registry; +package com.oath.micro.server.application.registry; import java.net.InetAddress; import java.net.UnknownHostException; @@ -16,8 +16,8 @@ import org.springframework.stereotype.Component; -import com.aol.micro.server.servers.ApplicationRegister; -import com.aol.micro.server.servers.model.ServerData; +import com.oath.micro.server.servers.ApplicationRegister; +import com.oath.micro.server.servers.model.ServerData; import lombok.Getter; diff --git a/micro-application-register/src/main/java/com/aol/micro/server/application/registry/Cleaner.java b/micro-application-register/src/main/java/com/oath/micro/server/application/registry/Cleaner.java similarity index 93% rename from micro-application-register/src/main/java/com/aol/micro/server/application/registry/Cleaner.java rename to micro-application-register/src/main/java/com/oath/micro/server/application/registry/Cleaner.java index 72d08d275..d8801ee8b 100644 --- a/micro-application-register/src/main/java/com/aol/micro/server/application/registry/Cleaner.java +++ b/micro-application-register/src/main/java/com/oath/micro/server/application/registry/Cleaner.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.application.registry; +package com.oath.micro.server.application.registry; import java.io.File; import java.util.Date; @@ -11,7 +11,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; -import com.aol.micro.server.rest.jackson.JacksonUtil; +import com.oath.micro.server.rest.jackson.JacksonUtil; @Component public class Cleaner { diff --git a/micro-application-register/src/main/java/com/aol/micro/server/application/registry/Finder.java b/micro-application-register/src/main/java/com/oath/micro/server/application/registry/Finder.java similarity index 93% rename from micro-application-register/src/main/java/com/aol/micro/server/application/registry/Finder.java rename to micro-application-register/src/main/java/com/oath/micro/server/application/registry/Finder.java index 8967749de..ecabee895 100644 --- a/micro-application-register/src/main/java/com/aol/micro/server/application/registry/Finder.java +++ b/micro-application-register/src/main/java/com/oath/micro/server/application/registry/Finder.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.application.registry; +package com.oath.micro.server.application.registry; import java.io.File; import java.util.ArrayList; @@ -15,7 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import com.aol.micro.server.rest.jackson.JacksonUtil; +import com.oath.micro.server.rest.jackson.JacksonUtil; @Component public class Finder { diff --git a/micro-application-register/src/main/java/com/oath/micro/server/application/registry/Health.java b/micro-application-register/src/main/java/com/oath/micro/server/application/registry/Health.java new file mode 100644 index 000000000..f7b56c504 --- /dev/null +++ b/micro-application-register/src/main/java/com/oath/micro/server/application/registry/Health.java @@ -0,0 +1,6 @@ +package com.oath.micro.server.application.registry; + +public enum Health { + + OK, ERROR +} diff --git a/micro-application-register/src/main/java/com/oath/micro/server/application/registry/Job.java b/micro-application-register/src/main/java/com/oath/micro/server/application/registry/Job.java new file mode 100644 index 000000000..7eaa47307 --- /dev/null +++ b/micro-application-register/src/main/java/com/oath/micro/server/application/registry/Job.java @@ -0,0 +1,80 @@ +package com.oath.micro.server.application.registry; + +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import javax.annotation.PostConstruct; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import com.oath.micro.server.rest.client.nio.AsyncRestClient; +import com.oath.micro.server.rest.jackson.JacksonUtil; + +@Component +public class Job { + + private final Logger logger = LoggerFactory.getLogger(getClass()); + private final AsyncRestClient rest = new AsyncRestClient( + 100, 2000); + private final String apiUrl; + private final ApplicationRegisterImpl app; + private final String uuid = UUID.randomUUID() + .toString(); + private final String resourcePath; + private final RegistryHealthChecker checker; + private final RegistryStatsChecker statsChecker; + + @Autowired + public Job(@Value("${service.registry.url:#{null}}") String apiUrl, ApplicationRegisterImpl app, + @Value("${resource.path:/service-registry/register}") String resourcePath, RegistryHealthChecker checker, + RegistryStatsChecker statsChecker) { + + this.apiUrl = apiUrl; + this.app = app; + this.resourcePath = resourcePath; + this.checker = checker; + this.statsChecker = statsChecker; + + } + + @PostConstruct + @Scheduled(fixedDelayString = "${service.registry.delay:1000}") + public synchronized void schedule() { + try { + if (app.getApplication() != null && apiUrl != null) + app.getApplication() + .forEach(moduleEntry -> sendPing(moduleEntry)); + } catch (Exception e) { + logger.error("Failed to register services due to exception {}", e.getMessage(), e); + } + } + + private void sendPing(RegisterEntry moduleEntry) { + final RegisterEntry entry = moduleEntry.withTime(new Date()) + .withUuid(uuid) + .withHealth(checker.isOk() ? Health.OK : Health.ERROR) + .withStats(nonEmptyOrNull(statsChecker.stats())); + try { + + logger.debug("Posting {} to " + apiUrl + resourcePath, JacksonUtil.serializeToJson(entry)); + rest.post(apiUrl + resourcePath, JacksonUtil.serializeToJson(entry)) + .join(); + } catch (Exception e) { + logger.warn("Failed posting {} to {}" + resourcePath, JacksonUtil.serializeToJson(entry), apiUrl); + + } + } + + private List>> nonEmptyOrNull(List>> stats) { + if (stats == null || stats.isEmpty()) + return null; + return stats; + } +} diff --git a/micro-application-register/src/main/java/com/aol/micro/server/application/registry/ManifestLoader.java b/micro-application-register/src/main/java/com/oath/micro/server/application/registry/ManifestLoader.java similarity index 97% rename from micro-application-register/src/main/java/com/aol/micro/server/application/registry/ManifestLoader.java rename to micro-application-register/src/main/java/com/oath/micro/server/application/registry/ManifestLoader.java index 501868241..7a871ee2c 100644 --- a/micro-application-register/src/main/java/com/aol/micro/server/application/registry/ManifestLoader.java +++ b/micro-application-register/src/main/java/com/oath/micro/server/application/registry/ManifestLoader.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.application.registry; +package com.oath.micro.server.application.registry; import java.io.InputStream; import java.util.HashMap; diff --git a/micro-application-register/src/main/java/com/aol/micro/server/application/registry/Register.java b/micro-application-register/src/main/java/com/oath/micro/server/application/registry/Register.java similarity index 86% rename from micro-application-register/src/main/java/com/aol/micro/server/application/registry/Register.java rename to micro-application-register/src/main/java/com/oath/micro/server/application/registry/Register.java index d148512b3..9923d59e8 100644 --- a/micro-application-register/src/main/java/com/aol/micro/server/application/registry/Register.java +++ b/micro-application-register/src/main/java/com/oath/micro/server/application/registry/Register.java @@ -1,18 +1,16 @@ -package com.aol.micro.server.application.registry; +package com.oath.micro.server.application.registry; import java.io.File; import java.io.IOException; -import lombok.val; - import org.apache.commons.io.FileUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import com.aol.micro.server.ip.tracker.*; -import com.aol.micro.server.rest.jackson.JacksonUtil; +import com.oath.micro.server.ip.tracker.*; +import com.oath.micro.server.rest.jackson.JacksonUtil; @Component diff --git a/micro-application-register/src/main/java/com/aol/micro/server/application/registry/RegisterConfig.java b/micro-application-register/src/main/java/com/oath/micro/server/application/registry/RegisterConfig.java similarity index 91% rename from micro-application-register/src/main/java/com/aol/micro/server/application/registry/RegisterConfig.java rename to micro-application-register/src/main/java/com/oath/micro/server/application/registry/RegisterConfig.java index 997c2d031..9f89d10a1 100644 --- a/micro-application-register/src/main/java/com/aol/micro/server/application/registry/RegisterConfig.java +++ b/micro-application-register/src/main/java/com/oath/micro/server/application/registry/RegisterConfig.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.application.registry; +package com.oath.micro.server.application.registry; import lombok.AccessLevel; import lombok.Getter; diff --git a/micro-application-register/src/main/java/com/aol/micro/server/application/registry/RegisterEntry.java b/micro-application-register/src/main/java/com/oath/micro/server/application/registry/RegisterEntry.java similarity index 97% rename from micro-application-register/src/main/java/com/aol/micro/server/application/registry/RegisterEntry.java rename to micro-application-register/src/main/java/com/oath/micro/server/application/registry/RegisterEntry.java index c30232bd1..aae1730ba 100644 --- a/micro-application-register/src/main/java/com/aol/micro/server/application/registry/RegisterEntry.java +++ b/micro-application-register/src/main/java/com/oath/micro/server/application/registry/RegisterEntry.java @@ -1,9 +1,8 @@ -package com.aol.micro.server.application.registry; +package com.oath.micro.server.application.registry; import java.text.SimpleDateFormat; import java.util.*; -import javax.ws.rs.QueryParam; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; diff --git a/micro-application-register/src/main/java/com/aol/micro/server/application/registry/RegistryHealthChecker.java b/micro-application-register/src/main/java/com/oath/micro/server/application/registry/RegistryHealthChecker.java similarity index 88% rename from micro-application-register/src/main/java/com/aol/micro/server/application/registry/RegistryHealthChecker.java rename to micro-application-register/src/main/java/com/oath/micro/server/application/registry/RegistryHealthChecker.java index 8514440be..91018bdb5 100644 --- a/micro-application-register/src/main/java/com/aol/micro/server/application/registry/RegistryHealthChecker.java +++ b/micro-application-register/src/main/java/com/oath/micro/server/application/registry/RegistryHealthChecker.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.application.registry; +package com.oath.micro.server.application.registry; import java.util.List; @@ -8,7 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import com.aol.micro.server.HealthStatusChecker; +import com.oath.micro.server.HealthStatusChecker; @Component public class RegistryHealthChecker { diff --git a/micro-application-register/src/main/java/com/aol/micro/server/application/registry/RegistryStatsChecker.java b/micro-application-register/src/main/java/com/oath/micro/server/application/registry/RegistryStatsChecker.java similarity index 91% rename from micro-application-register/src/main/java/com/aol/micro/server/application/registry/RegistryStatsChecker.java rename to micro-application-register/src/main/java/com/oath/micro/server/application/registry/RegistryStatsChecker.java index af0f6ad7f..b46dade41 100644 --- a/micro-application-register/src/main/java/com/aol/micro/server/application/registry/RegistryStatsChecker.java +++ b/micro-application-register/src/main/java/com/oath/micro/server/application/registry/RegistryStatsChecker.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.application.registry; +package com.oath.micro.server.application.registry; import java.util.List; import java.util.Map; @@ -10,7 +10,7 @@ import org.springframework.stereotype.Component; -import com.aol.micro.server.StatsSupplier; +import com.oath.micro.server.StatsSupplier; @Component public class RegistryStatsChecker { diff --git a/micro-application-register/src/main/java/com/aol/micro/server/application/registry/ServiceRegistryResource.java b/micro-application-register/src/main/java/com/oath/micro/server/application/registry/ServiceRegistryResource.java similarity index 86% rename from micro-application-register/src/main/java/com/aol/micro/server/application/registry/ServiceRegistryResource.java rename to micro-application-register/src/main/java/com/oath/micro/server/application/registry/ServiceRegistryResource.java index 5d3ed92ab..0bea25475 100644 --- a/micro-application-register/src/main/java/com/aol/micro/server/application/registry/ServiceRegistryResource.java +++ b/micro-application-register/src/main/java/com/oath/micro/server/application/registry/ServiceRegistryResource.java @@ -1,14 +1,11 @@ -package com.aol.micro.server.application.registry; +package com.oath.micro.server.application.registry; import java.util.Arrays; -import java.util.Optional; import javax.ws.rs.*; import javax.ws.rs.container.AsyncResponse; import javax.ws.rs.container.Suspended; import javax.ws.rs.core.Context; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.UriInfo; import cyclops.reactive.ReactiveSeq; @@ -17,11 +14,9 @@ import org.springframework.beans.factory.annotation.Autowired; -import com.aol.micro.server.WorkerThreads; -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.utility.HashMapBuilder; - -import static javax.ws.rs.core.Response.Status.*; +import com.oath.micro.server.WorkerThreads; +import com.oath.micro.server.auto.discovery.Rest; +import com.oath.micro.server.utility.HashMapBuilder; @Rest diff --git a/micro-application-register/src/main/java/com/aol/micro/server/application/registry/UriInfoParser.java b/micro-application-register/src/main/java/com/oath/micro/server/application/registry/UriInfoParser.java similarity index 97% rename from micro-application-register/src/main/java/com/aol/micro/server/application/registry/UriInfoParser.java rename to micro-application-register/src/main/java/com/oath/micro/server/application/registry/UriInfoParser.java index eab983026..738357302 100644 --- a/micro-application-register/src/main/java/com/aol/micro/server/application/registry/UriInfoParser.java +++ b/micro-application-register/src/main/java/com/oath/micro/server/application/registry/UriInfoParser.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.application.registry; +package com.oath.micro.server.application.registry; import cyclops.reactive.ReactiveSeq; diff --git a/micro-application-register/src/main/java/com/oath/micro/server/application/registry/plugin/ApplicationRegistryPlugin.java b/micro-application-register/src/main/java/com/oath/micro/server/application/registry/plugin/ApplicationRegistryPlugin.java new file mode 100644 index 000000000..75be4fd11 --- /dev/null +++ b/micro-application-register/src/main/java/com/oath/micro/server/application/registry/plugin/ApplicationRegistryPlugin.java @@ -0,0 +1,25 @@ +package com.oath.micro.server.application.registry.plugin; + +import com.oath.micro.server.Plugin; +import com.oath.micro.server.application.registry.ApplicationRegisterImpl; +import com.oath.micro.server.application.registry.Cleaner; +import com.oath.micro.server.application.registry.Finder; +import com.oath.micro.server.application.registry.RegistryHealthChecker; +import com.oath.micro.server.application.registry.Job; +import com.oath.micro.server.application.registry.Register; +import com.oath.micro.server.application.registry.RegisterConfig; +import com.oath.micro.server.application.registry.ServiceRegistryResource; +import com.oath.micro.server.application.registry.RegistryStatsChecker; +import cyclops.collections.mutable.SetX; + +import java.util.Set; + +public class ApplicationRegistryPlugin implements Plugin { + + @Override + public Set springClasses() { + return SetX.of(ApplicationRegisterImpl.class, Cleaner.class, Register.class, ServiceRegistryResource.class, + RegisterConfig.class, Job.class, Finder.class, RegistryHealthChecker.class, RegistryStatsChecker.class); + } + +} diff --git a/micro-application-register/src/main/resources/META-INF/services/com.aol.micro.server.Plugin b/micro-application-register/src/main/resources/META-INF/services/com.aol.micro.server.Plugin deleted file mode 100644 index 0118af46a..000000000 --- a/micro-application-register/src/main/resources/META-INF/services/com.aol.micro.server.Plugin +++ /dev/null @@ -1 +0,0 @@ -com.aol.micro.server.application.registry.plugin.ApplicationRegistryPlugin \ No newline at end of file diff --git a/micro-application-register/src/main/resources/META-INF/services/com.oath.micro.server.Plugin b/micro-application-register/src/main/resources/META-INF/services/com.oath.micro.server.Plugin new file mode 100644 index 000000000..5c1d6e16f --- /dev/null +++ b/micro-application-register/src/main/resources/META-INF/services/com.oath.micro.server.Plugin @@ -0,0 +1 @@ +com.oath.micro.server.application.registry.plugin.ApplicationRegistryPlugin \ No newline at end of file diff --git a/micro-application-register/src/test/java/app/registry/com/aol/micro/server/RegistryAppRunner.java b/micro-application-register/src/test/java/app/registry/com/aol/micro/server/RegistryAppRunner.java deleted file mode 100644 index f998808f0..000000000 --- a/micro-application-register/src/test/java/app/registry/com/aol/micro/server/RegistryAppRunner.java +++ /dev/null @@ -1,163 +0,0 @@ -package app.registry.com.aol.micro.server; - -import static java.util.stream.Collectors.joining; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.not; -import static org.junit.Assert.assertThat; - -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.List; -import java.util.concurrent.ExecutionException; -import java.util.stream.Stream; - -import com.aol.micro.server.rest.client.RestClient; -import com.fasterxml.jackson.core.type.TypeReference; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.application.registry.RegisterEntry; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.rest.client.nio.AsyncRestClient; -import com.aol.micro.server.rest.jackson.JacksonUtil; -import com.aol.micro.server.testing.RestAgent; - -@Microserver(properties = { "service.registry.url", "http://localhost:8080/registry-app", "target.endpoint", - "configured-target" }) -public class RegistryAppRunner { - - RestAgent rest = new RestAgent(); - private final AsyncRestClient restAsync = new AsyncRestClient(100, 2000); - MicroserverApp server; - - String baseUrl = "http://localhost:8080/registry-app/service-registry"; - - @Before - public void startServer() { - server = new MicroserverApp(() -> "registry-app"); - server.start(); - } - - @After - public void stopServer() { - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException { - - SimpleDateFormat f = new SimpleDateFormat("EEE"); - String date = f.format(new Date()); - Thread.sleep(1000); - - assertThat(rest.post(baseUrl + "/schedule"), is("{\"status\":\"success\"}")); - Thread.sleep(1000); - - String listResponse = rest.getJson(baseUrl + "/list"); - - assertThat(listResponse, containsString("[{\"port\":8080,")); - assertThat(listResponse, containsString("externalPort\":8080")); - - sendPing("1", 8081, "use-ip", "hello", "world", "my-target", 8082); - Thread.sleep(1000); - - listResponse = rest.getJson(baseUrl + "/list");; - - assertThat(listResponse, containsString("{\"port\":8081,")); - assertThat(listResponse, containsString("\"target\":\"my-target\"")); - assertThat(listResponse, containsString("\"target\":\"configured-target\"")); - assertThat(listResponse, not(containsString("\"hostname\":\"test-host\""))); - assertThat(listResponse, containsString("\"formattedDate\"")); - assertThat(listResponse, containsString("\"manifest\"")); - assertThat(listResponse, containsString("Manifest-Version")); - assertThat(listResponse, containsString(date)); - - } - - @Test - public void filterTest() throws Exception { - Thread.sleep(1000); - - List entries = list(); - assertThat(entries.size(), is(1)); - - sendPing("121", 8080, "host1", "module1", "context1", "target1", 9080); - sendPing("122", 8080, "host2", "module1", "context1", "target1", 9080); - sendPing("131", 6080, "host3", "module2", "context2", "target2", 7080); - sendPing("132", 6080, "host4", "module2", "context2", "target2", 7080); - - entries = list(); - assertThat(entries.size(), is(5)); - - entries = list("port=8080"); - assertThat(entries.size(), is(3)); - - entries = list("port=8080", "externalPort=9080"); - System.out.println(entries); - assertThat(entries.size(), is(2)); - - entries = list("port=8080", "externalPort=9080", "module=module", "context=context1"); - assertThat(entries.size(), is(2)); - - entries = list("port=8080", "externalPort=9080", "module=module", "context=context1", "hostname=host1"); - assertThat(entries.size(), is(1)); - - entries = list("port=8080", "externalPort=9080", "module=module1", "context=context2"); - assertThat(entries.size(), is(0)); - - entries = list("manifest.Implementation-Version=version"); - assertThat(entries.size(), is(4)); - - entries = list("manifest.Implementation-Version=version1"); - assertThat(entries.size(), is(4)); - - entries = list("manifest.Implementation-Version=version121"); - assertThat(entries.size(), is(1)); - - entries = list("manifest.Implementation-revision=rev12"); - assertThat(entries.size(), is(2)); - - entries = list("manifest.Implementation-Timestamp=2017_13"); - assertThat(entries.size(), is(2)); - - entries = list("health=OK"); - assertThat(entries.size(), is(5)); - - List list = JacksonUtil.convertFromJson(rest.getJson(baseUrl + "/list?port=OK"), new TypeReference>() {}); - assertThat(list.size(), is(1)); - assertThat(list.get(0), is("Bad Request: 'OK' is not a valid number.")); - - list = JacksonUtil.convertFromJson(rest.getJson(baseUrl + "/list?health=Suspended"), new TypeReference>() {}); - assertThat(list.size(), is(1)); - assertThat(list.get(0), is("Bad Request: 'Suspended' is not valid, valid values are [OK, ERROR]")); - } - - private List list(String... parameters) { - String url = baseUrl + "/list?" + Stream.of(parameters).collect(joining("&")); - return JacksonUtil.convertFromJson(rest.getJson(url), new TypeReference>() {}); - } - - private void sendPing(String uuid, int port, String hostName, String module, String context, String target, int externalPort) { - try { - RegisterEntry re = RegisterEntry.builder() - .port(port) - .hostname(hostName) - .module(module) - .context(context) - .time(new Date()) - .uuid(uuid) - .target(target) - .externalPort(externalPort) - .build(); - re.getManifest().put("Implementation-revision", "rev" + uuid); - re.getManifest().put("Implementation-Version", "version" + uuid); - re.getManifest().put("Implementation-Timestamp", "2017_" + uuid); - restAsync.post("http://localhost:8080/registry-app/service-registry/register", - JacksonUtil.serializeToJson(re)) - .get(); - } catch (Exception e) {} - } -} diff --git a/micro-application-register/src/test/java/app/registry/com/oath/micro/server/RegistryAppRunner.java b/micro-application-register/src/test/java/app/registry/com/oath/micro/server/RegistryAppRunner.java new file mode 100644 index 000000000..90efd2251 --- /dev/null +++ b/micro-application-register/src/test/java/app/registry/com/oath/micro/server/RegistryAppRunner.java @@ -0,0 +1,162 @@ +package app.registry.com.oath.micro.server; + +import static java.util.stream.Collectors.joining; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.junit.Assert.assertThat; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.List; +import java.util.concurrent.ExecutionException; +import java.util.stream.Stream; + +import com.fasterxml.jackson.core.type.TypeReference; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.application.registry.RegisterEntry; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.rest.client.nio.AsyncRestClient; +import com.oath.micro.server.rest.jackson.JacksonUtil; +import com.oath.micro.server.testing.RestAgent; + +@Microserver(properties = { "service.registry.url", "http://localhost:8080/registry-app", "target.endpoint", + "configured-target" }) +public class RegistryAppRunner { + + RestAgent rest = new RestAgent(); + private final AsyncRestClient restAsync = new AsyncRestClient(100, 2000); + MicroserverApp server; + + String baseUrl = "http://localhost:8080/registry-app/service-registry"; + + @Before + public void startServer() { + server = new MicroserverApp(() -> "registry-app"); + server.start(); + } + + @After + public void stopServer() { + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException { + + SimpleDateFormat f = new SimpleDateFormat("EEE"); + String date = f.format(new Date()); + Thread.sleep(1000); + + assertThat(rest.post(baseUrl + "/schedule"), is("{\"status\":\"success\"}")); + Thread.sleep(1000); + + String listResponse = rest.getJson(baseUrl + "/list"); + + assertThat(listResponse, containsString("[{\"port\":8080,")); + assertThat(listResponse, containsString("externalPort\":8080")); + + sendPing("1", 8081, "use-ip", "hello", "world", "my-target", 8082); + Thread.sleep(1000); + + listResponse = rest.getJson(baseUrl + "/list");; + + assertThat(listResponse, containsString("{\"port\":8081,")); + assertThat(listResponse, containsString("\"target\":\"my-target\"")); + assertThat(listResponse, containsString("\"target\":\"configured-target\"")); + assertThat(listResponse, not(containsString("\"hostname\":\"test-host\""))); + assertThat(listResponse, containsString("\"formattedDate\"")); + assertThat(listResponse, containsString("\"manifest\"")); + assertThat(listResponse, containsString("Manifest-Version")); + assertThat(listResponse, containsString(date)); + + } + + @Test + public void filterTest() throws Exception { + Thread.sleep(1000); + + List entries = list(); + assertThat(entries.size(), is(1)); + + sendPing("121", 8080, "host1", "module1", "context1", "target1", 9080); + sendPing("122", 8080, "host2", "module1", "context1", "target1", 9080); + sendPing("131", 6080, "host3", "module2", "context2", "target2", 7080); + sendPing("132", 6080, "host4", "module2", "context2", "target2", 7080); + + entries = list(); + assertThat(entries.size(), is(5)); + + entries = list("port=8080"); + assertThat(entries.size(), is(3)); + + entries = list("port=8080", "externalPort=9080"); + System.out.println(entries); + assertThat(entries.size(), is(2)); + + entries = list("port=8080", "externalPort=9080", "module=module", "context=context1"); + assertThat(entries.size(), is(2)); + + entries = list("port=8080", "externalPort=9080", "module=module", "context=context1", "hostname=host1"); + assertThat(entries.size(), is(1)); + + entries = list("port=8080", "externalPort=9080", "module=module1", "context=context2"); + assertThat(entries.size(), is(0)); + + entries = list("manifest.Implementation-Version=version"); + assertThat(entries.size(), is(4)); + + entries = list("manifest.Implementation-Version=version1"); + assertThat(entries.size(), is(4)); + + entries = list("manifest.Implementation-Version=version121"); + assertThat(entries.size(), is(1)); + + entries = list("manifest.Implementation-revision=rev12"); + assertThat(entries.size(), is(2)); + + entries = list("manifest.Implementation-Timestamp=2017_13"); + assertThat(entries.size(), is(2)); + + entries = list("health=OK"); + assertThat(entries.size(), is(5)); + + List list = JacksonUtil.convertFromJson(rest.getJson(baseUrl + "/list?port=OK"), new TypeReference>() {}); + assertThat(list.size(), is(1)); + assertThat(list.get(0), is("Bad Request: 'OK' is not a valid number.")); + + list = JacksonUtil.convertFromJson(rest.getJson(baseUrl + "/list?health=Suspended"), new TypeReference>() {}); + assertThat(list.size(), is(1)); + assertThat(list.get(0), is("Bad Request: 'Suspended' is not valid, valid values are [OK, ERROR]")); + } + + private List list(String... parameters) { + String url = baseUrl + "/list?" + Stream.of(parameters).collect(joining("&")); + return JacksonUtil.convertFromJson(rest.getJson(url), new TypeReference>() {}); + } + + private void sendPing(String uuid, int port, String hostName, String module, String context, String target, int externalPort) { + try { + RegisterEntry re = RegisterEntry.builder() + .port(port) + .hostname(hostName) + .module(module) + .context(context) + .time(new Date()) + .uuid(uuid) + .target(target) + .externalPort(externalPort) + .build(); + re.getManifest().put("Implementation-revision", "rev" + uuid); + re.getManifest().put("Implementation-Version", "version" + uuid); + re.getManifest().put("Implementation-Timestamp", "2017_" + uuid); + restAsync.post("http://localhost:8080/registry-app/service-registry/register", + JacksonUtil.serializeToJson(re)) + .get(); + } catch (Exception e) {} + } +} diff --git a/micro-application-register/src/test/java/app/registry/config/com/aol/micro/server/RegistryAppRunner.java b/micro-application-register/src/test/java/app/registry/config/com/aol/micro/server/RegistryAppRunner.java deleted file mode 100644 index d0bfaa0b4..000000000 --- a/micro-application-register/src/test/java/app/registry/config/com/aol/micro/server/RegistryAppRunner.java +++ /dev/null @@ -1,96 +0,0 @@ -package app.registry.config.com.aol.micro.server; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.not; -import static org.junit.Assert.assertThat; - -import java.util.Date; -import java.util.concurrent.ExecutionException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.application.registry.RegisterEntry; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.rest.client.nio.AsyncRestClient; -import com.aol.micro.server.rest.jackson.JacksonUtil; -import com.aol.micro.server.testing.RestAgent; - -@Microserver(properties = { "external.port.registry-app", "9090", "service.registry.url", - "http://localhost:8080/registry-app", "host.address", "test-host" }) -public class RegistryAppRunner { - - RestAgent rest = new RestAgent(); - private final AsyncRestClient restAsync = new AsyncRestClient( - 100, 2000); - MicroserverApp server; - - @Before - public void startServer() { - - server = new MicroserverApp( - () -> "registry-app"); - server.start(); - - } - - @After - public void stopServer() { - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException { - - Thread.sleep(1000); - - assertThat(rest.post("http://localhost:8080/registry-app/service-registry/schedule"), - is("{\"status\":\"success\"}")); - Thread.sleep(1000); - assertThat(rest.getJson("http://localhost:8080/registry-app/service-registry/list"), - containsString("[{\"port\":8080,")); - assertThat(rest.getJson("http://localhost:8080/registry-app/service-registry/list"), - containsString("externalPort\":9090")); - - sendPing(new RegisterEntry( - 8081, "use-ip", "hello", "world", new Date(), "my-target", 8082)); - Thread.sleep(1000); - System.out.println(rest.getJson("http://localhost:8080/registry-app/service-registry/list")); - assertThat(rest.getJson("http://localhost:8080/registry-app/service-registry/list"), - containsString("{\"port\":8081,")); - assertThat(rest.getJson("http://localhost:8080/registry-app/service-registry/list"), - containsString("\"hostname\":\"test-host\"")); - assertThat(rest.getJson("http://localhost:8080/registry-app/service-registry/list"), - containsString("\"health\":\"OK\"")); - assertThat(rest.getJson("http://localhost:8080/registry-app/service-registry/list"), - not(containsString("\"target\":\"configured-target\""))); - - assertThat(rest.getJson("http://localhost:8080/registry-app/service-registry/list"), - not(containsString("\"stats\""))); - rest.getJson("http://localhost:8080/health/error"); - rest.getJson("http://localhost:8080/health/stats"); - rest.post("http://localhost:8080/registry-app/service-registry/schedule"); - Thread.sleep(1000); - assertThat(rest.getJson("http://localhost:8080/registry-app/service-registry/list"), - containsString("\"health\":\"ERROR\"")); - assertThat(rest.getJson("http://localhost:8080/registry-app/service-registry/list"), - containsString("\"stats\"")); - - } - - private void sendPing(RegisterEntry entry) { - - try { - - restAsync.post("http://localhost:8080/registry-app/service-registry/register", - JacksonUtil.serializeToJson(entry)) - .join(); - } catch (Exception e) { - - } - } - -} diff --git a/micro-application-register/src/test/java/app/registry/config/com/aol/micro/server/HealthCheckerResource.java b/micro-application-register/src/test/java/app/registry/config/com/oath/micro/server/HealthCheckerResource.java similarity index 79% rename from micro-application-register/src/test/java/app/registry/config/com/aol/micro/server/HealthCheckerResource.java rename to micro-application-register/src/test/java/app/registry/config/com/oath/micro/server/HealthCheckerResource.java index bf6be2169..ca738d832 100644 --- a/micro-application-register/src/test/java/app/registry/config/com/aol/micro/server/HealthCheckerResource.java +++ b/micro-application-register/src/test/java/app/registry/config/com/oath/micro/server/HealthCheckerResource.java @@ -1,13 +1,13 @@ -package app.registry.config.com.aol.micro.server; +package app.registry.config.com.oath.micro.server; import java.util.Map; import javax.ws.rs.GET; import javax.ws.rs.Path; -import com.aol.micro.server.HealthStatusChecker; -import com.aol.micro.server.StatsSupplier; -import com.aol.micro.server.auto.discovery.Rest; +import com.oath.micro.server.HealthStatusChecker; +import com.oath.micro.server.StatsSupplier; +import com.oath.micro.server.auto.discovery.Rest; import cyclops.companion.MapXs; diff --git a/micro-application-register/src/test/java/app/registry/config/com/oath/micro/server/RegistryAppRunner.java b/micro-application-register/src/test/java/app/registry/config/com/oath/micro/server/RegistryAppRunner.java new file mode 100644 index 000000000..914c6dfeb --- /dev/null +++ b/micro-application-register/src/test/java/app/registry/config/com/oath/micro/server/RegistryAppRunner.java @@ -0,0 +1,96 @@ +package app.registry.config.com.oath.micro.server; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.junit.Assert.assertThat; + +import java.util.Date; +import java.util.concurrent.ExecutionException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.application.registry.RegisterEntry; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.rest.client.nio.AsyncRestClient; +import com.oath.micro.server.rest.jackson.JacksonUtil; +import com.oath.micro.server.testing.RestAgent; + +@Microserver(properties = { "external.port.registry-app", "9090", "service.registry.url", + "http://localhost:8080/registry-app", "host.address", "test-host" }) +public class RegistryAppRunner { + + RestAgent rest = new RestAgent(); + private final AsyncRestClient restAsync = new AsyncRestClient( + 100, 2000); + MicroserverApp server; + + @Before + public void startServer() { + + server = new MicroserverApp( + () -> "registry-app"); + server.start(); + + } + + @After + public void stopServer() { + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException { + + Thread.sleep(1000); + + assertThat(rest.post("http://localhost:8080/registry-app/service-registry/schedule"), + is("{\"status\":\"success\"}")); + Thread.sleep(1000); + assertThat(rest.getJson("http://localhost:8080/registry-app/service-registry/list"), + containsString("[{\"port\":8080,")); + assertThat(rest.getJson("http://localhost:8080/registry-app/service-registry/list"), + containsString("externalPort\":9090")); + + sendPing(new RegisterEntry( + 8081, "use-ip", "hello", "world", new Date(), "my-target", 8082)); + Thread.sleep(1000); + System.out.println(rest.getJson("http://localhost:8080/registry-app/service-registry/list")); + assertThat(rest.getJson("http://localhost:8080/registry-app/service-registry/list"), + containsString("{\"port\":8081,")); + assertThat(rest.getJson("http://localhost:8080/registry-app/service-registry/list"), + containsString("\"hostname\":\"test-host\"")); + assertThat(rest.getJson("http://localhost:8080/registry-app/service-registry/list"), + containsString("\"health\":\"OK\"")); + assertThat(rest.getJson("http://localhost:8080/registry-app/service-registry/list"), + not(containsString("\"target\":\"configured-target\""))); + + assertThat(rest.getJson("http://localhost:8080/registry-app/service-registry/list"), + not(containsString("\"stats\""))); + rest.getJson("http://localhost:8080/health/error"); + rest.getJson("http://localhost:8080/health/stats"); + rest.post("http://localhost:8080/registry-app/service-registry/schedule"); + Thread.sleep(1000); + assertThat(rest.getJson("http://localhost:8080/registry-app/service-registry/list"), + containsString("\"health\":\"ERROR\"")); + assertThat(rest.getJson("http://localhost:8080/registry-app/service-registry/list"), + containsString("\"stats\"")); + + } + + private void sendPing(RegisterEntry entry) { + + try { + + restAsync.post("http://localhost:8080/registry-app/service-registry/register", + JacksonUtil.serializeToJson(entry)) + .join(); + } catch (Exception e) { + + } + } + +} diff --git a/micro-application-register/src/test/java/com/aol/micro/server/testing/RestAgent.java b/micro-application-register/src/test/java/com/aol/micro/server/testing/RestAgent.java deleted file mode 100644 index 987e06335..000000000 --- a/micro-application-register/src/test/java/com/aol/micro/server/testing/RestAgent.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.aol.micro.server.testing; - -import java.util.List; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.Invocation.Builder; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; - -import com.aol.micro.server.rest.jackson.JacksonUtil; - -public class RestAgent { - - - public String getJson(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.get(String.class); - - } - - public String get(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.TEXT_PLAIN); - - return request.get(String.class); - - } - - public T post(String url, Object payload,Class type) { - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); - } - public String post(String url) { - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.post(null,String.class); - - } - - -} diff --git a/micro-application-register/src/test/java/com/aol/micro/server/application/registry/ApplicationRegisterTest.java b/micro-application-register/src/test/java/com/oath/micro/server/application/registry/ApplicationRegisterTest.java similarity index 91% rename from micro-application-register/src/test/java/com/aol/micro/server/application/registry/ApplicationRegisterTest.java rename to micro-application-register/src/test/java/com/oath/micro/server/application/registry/ApplicationRegisterTest.java index 58c5c5958..977675193 100644 --- a/micro-application-register/src/test/java/com/aol/micro/server/application/registry/ApplicationRegisterTest.java +++ b/micro-application-register/src/test/java/com/oath/micro/server/application/registry/ApplicationRegisterTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.application.registry; +package com.oath.micro.server.application.registry; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.nullValue; @@ -11,7 +11,7 @@ import org.junit.Before; import org.junit.Test; -import com.aol.micro.server.servers.model.ServerData; +import com.oath.micro.server.servers.model.ServerData; public class ApplicationRegisterTest { diff --git a/micro-application-register/src/test/java/com/aol/micro/server/application/registry/CleanerTest.java b/micro-application-register/src/test/java/com/oath/micro/server/application/registry/CleanerTest.java similarity index 97% rename from micro-application-register/src/test/java/com/aol/micro/server/application/registry/CleanerTest.java rename to micro-application-register/src/test/java/com/oath/micro/server/application/registry/CleanerTest.java index 98f1c3400..013a79994 100644 --- a/micro-application-register/src/test/java/com/aol/micro/server/application/registry/CleanerTest.java +++ b/micro-application-register/src/test/java/com/oath/micro/server/application/registry/CleanerTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.application.registry; +package com.oath.micro.server.application.registry; import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertThat; diff --git a/micro-application-register/src/test/java/com/aol/micro/server/application/registry/FinderTest.java b/micro-application-register/src/test/java/com/oath/micro/server/application/registry/FinderTest.java similarity index 96% rename from micro-application-register/src/test/java/com/aol/micro/server/application/registry/FinderTest.java rename to micro-application-register/src/test/java/com/oath/micro/server/application/registry/FinderTest.java index 064c2eb28..2265108a7 100644 --- a/micro-application-register/src/test/java/com/aol/micro/server/application/registry/FinderTest.java +++ b/micro-application-register/src/test/java/com/oath/micro/server/application/registry/FinderTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.application.registry; +package com.oath.micro.server.application.registry; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThan; diff --git a/micro-application-register/src/test/java/com/aol/micro/server/application/registry/RegisterEntryTest.java b/micro-application-register/src/test/java/com/oath/micro/server/application/registry/RegisterEntryTest.java similarity index 95% rename from micro-application-register/src/test/java/com/aol/micro/server/application/registry/RegisterEntryTest.java rename to micro-application-register/src/test/java/com/oath/micro/server/application/registry/RegisterEntryTest.java index de27b3007..0028b007a 100644 --- a/micro-application-register/src/test/java/com/aol/micro/server/application/registry/RegisterEntryTest.java +++ b/micro-application-register/src/test/java/com/oath/micro/server/application/registry/RegisterEntryTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.application.registry; +package com.oath.micro.server.application.registry; import static junit.framework.TestCase.assertFalse; import static org.junit.Assert.assertTrue; @@ -9,7 +9,7 @@ import org.junit.Before; import org.junit.Test; -import com.aol.micro.server.rest.jackson.JacksonUtil; +import com.oath.micro.server.rest.jackson.JacksonUtil; public class RegisterEntryTest { diff --git a/micro-application-register/src/test/java/com/aol/micro/server/application/registry/UriInfoParserTest.java b/micro-application-register/src/test/java/com/oath/micro/server/application/registry/UriInfoParserTest.java similarity index 96% rename from micro-application-register/src/test/java/com/aol/micro/server/application/registry/UriInfoParserTest.java rename to micro-application-register/src/test/java/com/oath/micro/server/application/registry/UriInfoParserTest.java index 218bc15c3..df07a1b47 100644 --- a/micro-application-register/src/test/java/com/aol/micro/server/application/registry/UriInfoParserTest.java +++ b/micro-application-register/src/test/java/com/oath/micro/server/application/registry/UriInfoParserTest.java @@ -1,13 +1,11 @@ -package com.aol.micro.server.application.registry; +package com.oath.micro.server.application.registry; import org.junit.Test; import org.mockito.Mockito; import javax.ws.rs.core.*; -import java.net.URI; import java.util.Arrays; -import java.util.List; import java.util.Optional; import static org.hamcrest.CoreMatchers.is; diff --git a/micro-application-register/src/test/java/com/aol/micro/server/application/registry/WriterTest.java b/micro-application-register/src/test/java/com/oath/micro/server/application/registry/WriterTest.java similarity index 96% rename from micro-application-register/src/test/java/com/aol/micro/server/application/registry/WriterTest.java rename to micro-application-register/src/test/java/com/oath/micro/server/application/registry/WriterTest.java index 7c1b09ae1..d69850582 100644 --- a/micro-application-register/src/test/java/com/aol/micro/server/application/registry/WriterTest.java +++ b/micro-application-register/src/test/java/com/oath/micro/server/application/registry/WriterTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.application.registry; +package com.oath.micro.server.application.registry; import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertThat; diff --git a/micro-application-register/src/test/java/com/oath/micro/server/testing/RestAgent.java b/micro-application-register/src/test/java/com/oath/micro/server/testing/RestAgent.java new file mode 100644 index 000000000..e48fe067f --- /dev/null +++ b/micro-application-register/src/test/java/com/oath/micro/server/testing/RestAgent.java @@ -0,0 +1,64 @@ +package com.oath.micro.server.testing; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.Invocation.Builder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; + +import com.oath.micro.server.rest.jackson.JacksonUtil; + +public class RestAgent { + + + public String getJson(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.get(String.class); + + } + + public String get(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.TEXT_PLAIN); + + return request.get(String.class); + + } + + public T post(String url, Object payload,Class type) { + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); + } + public String post(String url) { + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.post(null,String.class); + + } + + +} diff --git a/micro-async-data-loader/src/main/java/com/aol/micro/server/async/data/loader/ConditionallyLoad.java b/micro-async-data-loader/src/main/java/com/aol/micro/server/async/data/loader/ConditionallyLoad.java deleted file mode 100644 index 7c9dd6e68..000000000 --- a/micro-async-data-loader/src/main/java/com/aol/micro/server/async/data/loader/ConditionallyLoad.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.aol.micro.server.async.data.loader; - -public interface ConditionallyLoad { - - public boolean shouldLoad(); -} diff --git a/micro-async-data-loader/src/main/java/com/aol/micro/server/async/data/loader/plugin/AsyncDataLoaderPlugin.java b/micro-async-data-loader/src/main/java/com/aol/micro/server/async/data/loader/plugin/AsyncDataLoaderPlugin.java deleted file mode 100644 index 0241bff4b..000000000 --- a/micro-async-data-loader/src/main/java/com/aol/micro/server/async/data/loader/plugin/AsyncDataLoaderPlugin.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.aol.micro.server.async.data.loader.plugin; - -import java.util.Set; - - -import com.aol.micro.server.Plugin; -import com.aol.micro.server.async.data.loader.ConfigureSchedulingAsyncDataLoader; -import cyclops.collections.mutable.SetX; - -public class AsyncDataLoaderPlugin implements Plugin { - - @Override - public Set springClasses() { - return SetX.of(ConfigureSchedulingAsyncDataLoader.class); - } - -} diff --git a/micro-async-data-loader/src/main/java/com/oath/micro/server/async/data/loader/ConditionallyLoad.java b/micro-async-data-loader/src/main/java/com/oath/micro/server/async/data/loader/ConditionallyLoad.java new file mode 100644 index 000000000..780eec150 --- /dev/null +++ b/micro-async-data-loader/src/main/java/com/oath/micro/server/async/data/loader/ConditionallyLoad.java @@ -0,0 +1,6 @@ +package com.oath.micro.server.async.data.loader; + +public interface ConditionallyLoad { + + public boolean shouldLoad(); +} diff --git a/micro-async-data-loader/src/main/java/com/aol/micro/server/async/data/loader/ConfigureSchedulingAsyncDataLoader.java b/micro-async-data-loader/src/main/java/com/oath/micro/server/async/data/loader/ConfigureSchedulingAsyncDataLoader.java similarity index 95% rename from micro-async-data-loader/src/main/java/com/aol/micro/server/async/data/loader/ConfigureSchedulingAsyncDataLoader.java rename to micro-async-data-loader/src/main/java/com/oath/micro/server/async/data/loader/ConfigureSchedulingAsyncDataLoader.java index d676d3e64..f08fef185 100644 --- a/micro-async-data-loader/src/main/java/com/aol/micro/server/async/data/loader/ConfigureSchedulingAsyncDataLoader.java +++ b/micro-async-data-loader/src/main/java/com/oath/micro/server/async/data/loader/ConfigureSchedulingAsyncDataLoader.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.async.data.loader; +package com.oath.micro.server.async.data.loader; import java.util.List; import java.util.concurrent.Executors; @@ -13,7 +13,7 @@ import org.springframework.context.annotation.Configuration; -import com.aol.micro.server.manifest.ManifestComparator; +import com.oath.micro.server.manifest.ManifestComparator; import com.google.common.eventbus.EventBus; @Configuration diff --git a/micro-async-data-loader/src/main/java/com/aol/micro/server/async/data/loader/DataLoader.java b/micro-async-data-loader/src/main/java/com/oath/micro/server/async/data/loader/DataLoader.java similarity index 87% rename from micro-async-data-loader/src/main/java/com/aol/micro/server/async/data/loader/DataLoader.java rename to micro-async-data-loader/src/main/java/com/oath/micro/server/async/data/loader/DataLoader.java index b720c1f36..a024b33e1 100644 --- a/micro-async-data-loader/src/main/java/com/aol/micro/server/async/data/loader/DataLoader.java +++ b/micro-async-data-loader/src/main/java/com/oath/micro/server/async/data/loader/DataLoader.java @@ -1,13 +1,13 @@ -package com.aol.micro.server.async.data.loader; +package com.oath.micro.server.async.data.loader; import java.util.Random; import java.util.function.Supplier; -import com.aol.micro.server.events.ScheduledJob; -import com.aol.micro.server.events.SystemData; -import com.aol.micro.server.manifest.ManifestComparator; -import com.aol.micro.server.utility.HashMapBuilder; +import com.oath.micro.server.events.ScheduledJob; +import com.oath.micro.server.events.SystemData; +import com.oath.micro.server.manifest.ManifestComparator; +import com.oath.micro.server.utility.HashMapBuilder; import cyclops.collections.mutable.MapX; import lombok.AllArgsConstructor; diff --git a/micro-async-data-loader/src/main/java/com/aol/micro/server/async/data/loader/LoaderSchedular.java b/micro-async-data-loader/src/main/java/com/oath/micro/server/async/data/loader/LoaderSchedular.java similarity index 91% rename from micro-async-data-loader/src/main/java/com/aol/micro/server/async/data/loader/LoaderSchedular.java rename to micro-async-data-loader/src/main/java/com/oath/micro/server/async/data/loader/LoaderSchedular.java index e19e80f93..dc76ef7f0 100644 --- a/micro-async-data-loader/src/main/java/com/aol/micro/server/async/data/loader/LoaderSchedular.java +++ b/micro-async-data-loader/src/main/java/com/oath/micro/server/async/data/loader/LoaderSchedular.java @@ -1,9 +1,9 @@ -package com.aol.micro.server.async.data.loader; +package com.oath.micro.server.async.data.loader; import java.util.concurrent.ScheduledExecutorService; -import com.aol.micro.server.events.SystemData; +import com.oath.micro.server.events.SystemData; import com.google.common.eventbus.EventBus; import cyclops.collections.mutable.ListX; diff --git a/micro-async-data-loader/src/main/java/com/oath/micro/server/async/data/loader/plugin/AsyncDataLoaderPlugin.java b/micro-async-data-loader/src/main/java/com/oath/micro/server/async/data/loader/plugin/AsyncDataLoaderPlugin.java new file mode 100644 index 000000000..e1ea95a06 --- /dev/null +++ b/micro-async-data-loader/src/main/java/com/oath/micro/server/async/data/loader/plugin/AsyncDataLoaderPlugin.java @@ -0,0 +1,17 @@ +package com.oath.micro.server.async.data.loader.plugin; + +import java.util.Set; + + +import com.oath.micro.server.Plugin; +import com.oath.micro.server.async.data.loader.ConfigureSchedulingAsyncDataLoader; +import cyclops.collections.mutable.SetX; + +public class AsyncDataLoaderPlugin implements Plugin { + + @Override + public Set springClasses() { + return SetX.of(ConfigureSchedulingAsyncDataLoader.class); + } + +} diff --git a/micro-async-data-loader/src/main/resources/META-INF/services/com.aol.micro.server.Plugin b/micro-async-data-loader/src/main/resources/META-INF/services/com.aol.micro.server.Plugin deleted file mode 100644 index 7b8929016..000000000 --- a/micro-async-data-loader/src/main/resources/META-INF/services/com.aol.micro.server.Plugin +++ /dev/null @@ -1 +0,0 @@ -com.aol.micro.server.async.data.loader.plugin.AsyncDataLoaderPlugin \ No newline at end of file diff --git a/micro-async-data-loader/src/main/resources/META-INF/services/com.oath.micro.server.Plugin b/micro-async-data-loader/src/main/resources/META-INF/services/com.oath.micro.server.Plugin new file mode 100644 index 000000000..eeb768665 --- /dev/null +++ b/micro-async-data-loader/src/main/resources/META-INF/services/com.oath.micro.server.Plugin @@ -0,0 +1 @@ +com.oath.micro.server.async.data.loader.plugin.AsyncDataLoaderPlugin \ No newline at end of file diff --git a/micro-async-data-loader/src/test/java/app/loader/configured/com/aol/micro/server/ManifestComparatorResource.java b/micro-async-data-loader/src/test/java/app/loader/configured/com/aol/micro/server/ManifestComparatorResource.java deleted file mode 100644 index b5c3fa2f9..000000000 --- a/micro-async-data-loader/src/test/java/app/loader/configured/com/aol/micro/server/ManifestComparatorResource.java +++ /dev/null @@ -1,42 +0,0 @@ -package app.loader.configured.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; - -import org.springframework.beans.factory.annotation.Autowired; - -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.manifest.ManifestComparator; - -@Path("/comparator") -@Rest -public class ManifestComparatorResource { - - private volatile int count = 1; - private final ManifestComparator comparator; - - @Autowired - public ManifestComparatorResource(ManifestComparator comparator) { - this.comparator = comparator; - } - - @GET - @Path("/increment") - public String bucket() { - comparator.saveAndIncrement("hello" + (count++)); - return "incremented"; - } - - @GET - @Path("/get") - public String get() { - return comparator.getData(); - } - - @GET - @Path("/check") - public String check() { - return "" + !comparator.isOutOfDate(); - - } -} diff --git a/micro-async-data-loader/src/test/java/app/loader/configured/com/aol/micro/server/ManifestComparatorRunnerTest.java b/micro-async-data-loader/src/test/java/app/loader/configured/com/aol/micro/server/ManifestComparatorRunnerTest.java deleted file mode 100644 index 471f6f14f..000000000 --- a/micro-async-data-loader/src/test/java/app/loader/configured/com/aol/micro/server/ManifestComparatorRunnerTest.java +++ /dev/null @@ -1,64 +0,0 @@ -package app.loader.configured.com.aol.micro.server; - -import static org.hamcrest.CoreMatchers.equalTo; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import org.couchbase.mock.CouchbaseMock; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.testing.RestAgent; - -@Microserver(properties = { "couchbaseServers", "http://localhost:8091/pools", "couchbasePassword", "", - "couchbaseBucket", "beer-sample", "couchbase.manifest.comparison.key", "test-key", - "async.data.schedular.cron.loader", "* * * * * ?" }) -public class ManifestComparatorRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - - @Before - public void startServer() { - try { - // couchbase already running? - rest.get("http://localhost:8091/pools"); - } catch (Exception e) { - // start mock couchbase - CouchbaseMock.main(new String[] { "-S" }); - } - server = new MicroserverApp( - () -> "simple-app"); - - server.start(); - - } - - @After - public void stopServer() { - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException { - rest.get("http://localhost:8080/simple-app/comparator/increment"); - - assertThat(rest.get("http://localhost:8080/simple-app/comparator/check"), equalTo("true")); - assertThat(rest.get("http://localhost:8080/simple-app/comparator/get"), equalTo("hello1")); - rest.get("http://localhost:8080/simple-app/comparator/increment"); - assertThat(rest.get("http://localhost:8080/simple-app/comparator/get"), equalTo("hello2")); - - rest.get("http://localhost:8080/simple-app/comparator2/increment"); - - assertThat(rest.get("http://localhost:8080/simple-app/comparator/check"), equalTo("false")); - Thread.sleep(2000); - assertThat(rest.get("http://localhost:8080/simple-app/comparator/get"), equalTo("hellob")); - - } - -} diff --git a/micro-async-data-loader/src/test/java/app/loader/configured/com/aol/micro/server/SecondComparatorResource.java b/micro-async-data-loader/src/test/java/app/loader/configured/com/aol/micro/server/SecondComparatorResource.java deleted file mode 100644 index 3551309d9..000000000 --- a/micro-async-data-loader/src/test/java/app/loader/configured/com/aol/micro/server/SecondComparatorResource.java +++ /dev/null @@ -1,44 +0,0 @@ -package app.loader.configured.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; - -import org.springframework.beans.factory.annotation.Autowired; - -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.manifest.ManifestComparator; - -@Path("/comparator2") -@Rest -public class SecondComparatorResource { - - private final ManifestComparator comparator; - - @Autowired - public SecondComparatorResource(ManifestComparator comparator) { - this.comparator = comparator.withKey("test-key"); - } - - @GET - @Path("/increment") - public String bucket() { - comparator.saveAndIncrement("hellob"); - return "increment"; - } - - @GET - @Path("/get") - public String get() { - comparator.load(); - return comparator.getData() - .toString(); - - } - - @GET - @Path("/check") - public String check() { - return "" + !comparator.isOutOfDate(); - - } -} \ No newline at end of file diff --git a/micro-async-data-loader/src/test/java/app/loader/configured/com/oath/micro/server/ManifestComparatorResource.java b/micro-async-data-loader/src/test/java/app/loader/configured/com/oath/micro/server/ManifestComparatorResource.java new file mode 100644 index 000000000..172d7deb0 --- /dev/null +++ b/micro-async-data-loader/src/test/java/app/loader/configured/com/oath/micro/server/ManifestComparatorResource.java @@ -0,0 +1,42 @@ +package app.loader.configured.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +import org.springframework.beans.factory.annotation.Autowired; + +import com.oath.micro.server.auto.discovery.Rest; +import com.oath.micro.server.manifest.ManifestComparator; + +@Path("/comparator") +@Rest +public class ManifestComparatorResource { + + private volatile int count = 1; + private final ManifestComparator comparator; + + @Autowired + public ManifestComparatorResource(ManifestComparator comparator) { + this.comparator = comparator; + } + + @GET + @Path("/increment") + public String bucket() { + comparator.saveAndIncrement("hello" + (count++)); + return "incremented"; + } + + @GET + @Path("/get") + public String get() { + return comparator.getData(); + } + + @GET + @Path("/check") + public String check() { + return "" + !comparator.isOutOfDate(); + + } +} diff --git a/micro-async-data-loader/src/test/java/app/loader/configured/com/oath/micro/server/ManifestComparatorRunnerTest.java b/micro-async-data-loader/src/test/java/app/loader/configured/com/oath/micro/server/ManifestComparatorRunnerTest.java new file mode 100644 index 000000000..4b59e4827 --- /dev/null +++ b/micro-async-data-loader/src/test/java/app/loader/configured/com/oath/micro/server/ManifestComparatorRunnerTest.java @@ -0,0 +1,64 @@ +package app.loader.configured.com.oath.micro.server; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import org.couchbase.mock.CouchbaseMock; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.testing.RestAgent; + +@Microserver(properties = { "couchbaseServers", "http://localhost:8091/pools", "couchbasePassword", "", + "couchbaseBucket", "beer-sample", "couchbase.manifest.comparison.key", "test-key", + "async.data.schedular.cron.loader", "* * * * * ?" }) +public class ManifestComparatorRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + + @Before + public void startServer() { + try { + // couchbase already running? + rest.get("http://localhost:8091/pools"); + } catch (Exception e) { + // start mock couchbase + CouchbaseMock.main(new String[] { "-S" }); + } + server = new MicroserverApp( + () -> "simple-app"); + + server.start(); + + } + + @After + public void stopServer() { + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException { + rest.get("http://localhost:8080/simple-app/comparator/increment"); + + assertThat(rest.get("http://localhost:8080/simple-app/comparator/check"), equalTo("true")); + assertThat(rest.get("http://localhost:8080/simple-app/comparator/get"), equalTo("hello1")); + rest.get("http://localhost:8080/simple-app/comparator/increment"); + assertThat(rest.get("http://localhost:8080/simple-app/comparator/get"), equalTo("hello2")); + + rest.get("http://localhost:8080/simple-app/comparator2/increment"); + + assertThat(rest.get("http://localhost:8080/simple-app/comparator/check"), equalTo("false")); + Thread.sleep(2000); + assertThat(rest.get("http://localhost:8080/simple-app/comparator/get"), equalTo("hellob")); + + } + +} diff --git a/micro-async-data-loader/src/test/java/app/loader/configured/com/oath/micro/server/SecondComparatorResource.java b/micro-async-data-loader/src/test/java/app/loader/configured/com/oath/micro/server/SecondComparatorResource.java new file mode 100644 index 000000000..3f1d71856 --- /dev/null +++ b/micro-async-data-loader/src/test/java/app/loader/configured/com/oath/micro/server/SecondComparatorResource.java @@ -0,0 +1,44 @@ +package app.loader.configured.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +import org.springframework.beans.factory.annotation.Autowired; + +import com.oath.micro.server.auto.discovery.Rest; +import com.oath.micro.server.manifest.ManifestComparator; + +@Path("/comparator2") +@Rest +public class SecondComparatorResource { + + private final ManifestComparator comparator; + + @Autowired + public SecondComparatorResource(ManifestComparator comparator) { + this.comparator = comparator.withKey("test-key"); + } + + @GET + @Path("/increment") + public String bucket() { + comparator.saveAndIncrement("hellob"); + return "increment"; + } + + @GET + @Path("/get") + public String get() { + comparator.load(); + return comparator.getData() + .toString(); + + } + + @GET + @Path("/check") + public String check() { + return "" + !comparator.isOutOfDate(); + + } +} \ No newline at end of file diff --git a/micro-async-data-loader/src/test/java/app/loader/scheduled/com/aol/micro/server/CouchbaseResource.java b/micro-async-data-loader/src/test/java/app/loader/scheduled/com/aol/micro/server/CouchbaseResource.java deleted file mode 100644 index 7b5e218ec..000000000 --- a/micro-async-data-loader/src/test/java/app/loader/scheduled/com/aol/micro/server/CouchbaseResource.java +++ /dev/null @@ -1,65 +0,0 @@ -package app.loader.scheduled.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import cyclops.collections.immutable.LinkedListX; -import cyclops.control.Maybe; -import org.springframework.beans.factory.annotation.Autowired; - - - -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.distributed.DistributedMap; -import com.aol.micro.server.events.SystemData; -import com.google.common.eventbus.EventBus; -import com.google.common.eventbus.Subscribe; - -@Path("/couchbase") -@Rest -public class CouchbaseResource { - - private final DistributedMap client; - private volatile LinkedListX dataLoads = LinkedListX.empty(); - - @Autowired - public CouchbaseResource(DistributedMap client, EventBus bus) { - this.client = client; - bus.register(this); - } - - @Subscribe - public synchronized void events(SystemData event) { - dataLoads = dataLoads.plus(event); - - } - - @GET - @Path("/loading-events") - @Produces("application/json") - public synchronized LinkedListX loadingEvents() { - return dataLoads; - } - - @GET - @Path("/maybe") - @Produces("application/json") - public Maybe maybe() { - return Maybe.just("hello-world"); - } - - @GET - @Path("/get") - public String bucket() { - return client.get("hello") - .toString(); - } - - @GET - @Path("/put") - public String put() { - client.put("hello", "world"); - return "added"; - } -} diff --git a/micro-async-data-loader/src/test/java/app/loader/scheduled/com/aol/micro/server/CouchbaseRunnerTest.java b/micro-async-data-loader/src/test/java/app/loader/scheduled/com/aol/micro/server/CouchbaseRunnerTest.java deleted file mode 100644 index a9888fd2f..000000000 --- a/micro-async-data-loader/src/test/java/app/loader/scheduled/com/aol/micro/server/CouchbaseRunnerTest.java +++ /dev/null @@ -1,66 +0,0 @@ -package app.loader.scheduled.com.aol.micro.server; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - -import java.util.List; -import java.util.concurrent.ExecutionException; - -import org.couchbase.mock.CouchbaseMock; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.rest.jackson.JacksonUtil; -import com.aol.micro.server.testing.RestAgent; - -@Microserver(properties = { "couchbaseServers", "http://localhost:8091/pools", "couchbasePassword", "", - "couchbaseBucket", "beer-sample", "async.data.schedular.cron.loader", "* * * * * ?", - "async.data.schedular.cron.cleaner", "* * * * * ?" }) -public class CouchbaseRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - - @Before - public void startServer() { - try { - // couchbase already running? - rest.get("http://localhost:8091/pools"); - } catch (Exception e) { - // start mock couchbase - CouchbaseMock.main(new String[] { "-S" }); - } - server = new MicroserverApp( - ConfigurableModule.builder() - .context("simple-app") - .build()); - - server.start(); - - } - - @After - public void stopServer() { - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException { - rest.get("http://localhost:8080/simple-app/couchbase/put"); - assertThat(rest.get("http://localhost:8080/simple-app/couchbase/get"), containsString("world")); - - Thread.sleep(2000); - String json = rest.getJson("http://localhost:8080/simple-app/couchbase/loading-events"); - List list = JacksonUtil.convertFromJson(json, List.class); - System.out.println(list); - assertTrue(list.size() > 0); - - } - -} diff --git a/micro-async-data-loader/src/test/java/app/loader/scheduled/com/oath/micro/server/CouchbaseResource.java b/micro-async-data-loader/src/test/java/app/loader/scheduled/com/oath/micro/server/CouchbaseResource.java new file mode 100644 index 000000000..eda3bc8ad --- /dev/null +++ b/micro-async-data-loader/src/test/java/app/loader/scheduled/com/oath/micro/server/CouchbaseResource.java @@ -0,0 +1,65 @@ +package app.loader.scheduled.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import cyclops.collections.immutable.LinkedListX; +import cyclops.control.Maybe; +import org.springframework.beans.factory.annotation.Autowired; + + + +import com.oath.micro.server.auto.discovery.Rest; +import com.oath.micro.server.distributed.DistributedMap; +import com.oath.micro.server.events.SystemData; +import com.google.common.eventbus.EventBus; +import com.google.common.eventbus.Subscribe; + +@Path("/couchbase") +@Rest +public class CouchbaseResource { + + private final DistributedMap client; + private volatile LinkedListX dataLoads = LinkedListX.empty(); + + @Autowired + public CouchbaseResource(DistributedMap client, EventBus bus) { + this.client = client; + bus.register(this); + } + + @Subscribe + public synchronized void events(SystemData event) { + dataLoads = dataLoads.plus(event); + + } + + @GET + @Path("/loading-events") + @Produces("application/json") + public synchronized LinkedListX loadingEvents() { + return dataLoads; + } + + @GET + @Path("/maybe") + @Produces("application/json") + public Maybe maybe() { + return Maybe.just("hello-world"); + } + + @GET + @Path("/get") + public String bucket() { + return client.get("hello") + .toString(); + } + + @GET + @Path("/put") + public String put() { + client.put("hello", "world"); + return "added"; + } +} diff --git a/micro-async-data-loader/src/test/java/app/loader/scheduled/com/oath/micro/server/CouchbaseRunnerTest.java b/micro-async-data-loader/src/test/java/app/loader/scheduled/com/oath/micro/server/CouchbaseRunnerTest.java new file mode 100644 index 000000000..0d1989494 --- /dev/null +++ b/micro-async-data-loader/src/test/java/app/loader/scheduled/com/oath/micro/server/CouchbaseRunnerTest.java @@ -0,0 +1,66 @@ +package app.loader.scheduled.com.oath.micro.server; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; + +import java.util.List; +import java.util.concurrent.ExecutionException; + +import org.couchbase.mock.CouchbaseMock; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.module.ConfigurableModule; +import com.oath.micro.server.rest.jackson.JacksonUtil; +import com.oath.micro.server.testing.RestAgent; + +@Microserver(properties = { "couchbaseServers", "http://localhost:8091/pools", "couchbasePassword", "", + "couchbaseBucket", "beer-sample", "async.data.schedular.cron.loader", "* * * * * ?", + "async.data.schedular.cron.cleaner", "* * * * * ?" }) +public class CouchbaseRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + + @Before + public void startServer() { + try { + // couchbase already running? + rest.get("http://localhost:8091/pools"); + } catch (Exception e) { + // start mock couchbase + CouchbaseMock.main(new String[] { "-S" }); + } + server = new MicroserverApp( + ConfigurableModule.builder() + .context("simple-app") + .build()); + + server.start(); + + } + + @After + public void stopServer() { + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException { + rest.get("http://localhost:8080/simple-app/couchbase/put"); + assertThat(rest.get("http://localhost:8080/simple-app/couchbase/get"), containsString("world")); + + Thread.sleep(2000); + String json = rest.getJson("http://localhost:8080/simple-app/couchbase/loading-events"); + List list = JacksonUtil.convertFromJson(json, List.class); + System.out.println(list); + assertTrue(list.size() > 0); + + } + +} diff --git a/micro-async-data-loader/src/test/java/app/loader/scheduled/off/com/aol/micro/server/CouchbaseResource.java b/micro-async-data-loader/src/test/java/app/loader/scheduled/off/com/aol/micro/server/CouchbaseResource.java deleted file mode 100644 index 190d1eb13..000000000 --- a/micro-async-data-loader/src/test/java/app/loader/scheduled/off/com/aol/micro/server/CouchbaseResource.java +++ /dev/null @@ -1,65 +0,0 @@ -package app.loader.scheduled.off.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import cyclops.collections.immutable.LinkedListX; -import cyclops.control.Maybe; -import org.springframework.beans.factory.annotation.Autowired; - - -import com.aol.micro.server.async.data.loader.DataLoader; -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.distributed.DistributedMap; -import com.aol.micro.server.events.SystemData; -import com.google.common.eventbus.EventBus; -import com.google.common.eventbus.Subscribe; - -@Path("/couchbase") -@Rest -public class CouchbaseResource { - - private final DistributedMap client; - private volatile LinkedListX dataLoads = LinkedListX.empty(); - - @Autowired - public CouchbaseResource(DistributedMap client, EventBus bus) { - this.client = client; - bus.register(this); - } - - @Subscribe - public synchronized void events(SystemData event) { - dataLoads = dataLoads.plus(event); - - } - - @GET - @Path("/loading-events") - @Produces("application/json") - public synchronized LinkedListX loadingEvents() { - return dataLoads; - } - - @GET - @Path("/maybe") - @Produces("application/json") - public Maybe maybe() { - return Maybe.just("hello-world"); - } - - @GET - @Path("/get") - public String bucket() { - return client.get("hello") - .toString(); - } - - @GET - @Path("/put") - public String put() { - client.put("hello", "world"); - return "added"; - } -} diff --git a/micro-async-data-loader/src/test/java/app/loader/scheduled/off/com/aol/micro/server/CouchbaseRunnerTest.java b/micro-async-data-loader/src/test/java/app/loader/scheduled/off/com/aol/micro/server/CouchbaseRunnerTest.java deleted file mode 100644 index 057b9243b..000000000 --- a/micro-async-data-loader/src/test/java/app/loader/scheduled/off/com/aol/micro/server/CouchbaseRunnerTest.java +++ /dev/null @@ -1,66 +0,0 @@ -package app.loader.scheduled.off.com.aol.micro.server; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - -import java.util.List; -import java.util.concurrent.ExecutionException; - -import org.couchbase.mock.CouchbaseMock; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.rest.jackson.JacksonUtil; -import com.aol.micro.server.testing.RestAgent; - -@Microserver(properties = { "couchbaseServers", "http://localhost:8091/pools", "couchbasePassword", "", - "couchbaseBucket", "beer-sample", "async.data.schedular.cron.loader", "* * * * * ?", - "async.data.schedular.cron.cleaner", "* * * * * ?" }) -public class CouchbaseRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - - @Before - public void startServer() { - try { - // couchbase already running? - rest.get("http://localhost:8091/pools"); - } catch (Exception e) { - // start mock couchbase - CouchbaseMock.main(new String[] { "-S" }); - } - server = new MicroserverApp( - ConfigurableModule.builder() - .context("simple-app") - .build()); - - server.start(); - - } - - @After - public void stopServer() { - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException { - rest.get("http://localhost:8080/simple-app/couchbase/put"); - assertThat(rest.get("http://localhost:8080/simple-app/couchbase/get"), containsString("world")); - - Thread.sleep(2000); - String json = rest.getJson("http://localhost:8080/simple-app/couchbase/loading-events"); - List list = JacksonUtil.convertFromJson(json, List.class); - System.out.println(list); - assertTrue(list.size() == 0); - - } - -} diff --git a/micro-async-data-loader/src/test/java/app/loader/scheduled/off/com/aol/micro/server/TurnOff.java b/micro-async-data-loader/src/test/java/app/loader/scheduled/off/com/aol/micro/server/TurnOff.java deleted file mode 100644 index bcd1f512b..000000000 --- a/micro-async-data-loader/src/test/java/app/loader/scheduled/off/com/aol/micro/server/TurnOff.java +++ /dev/null @@ -1,15 +0,0 @@ -package app.loader.scheduled.off.com.aol.micro.server; - -import org.springframework.stereotype.Component; - -import com.aol.micro.server.async.data.loader.ConditionallyLoad; - -@Component -public class TurnOff implements ConditionallyLoad { - - @Override - public boolean shouldLoad() { - return false; - } - -} diff --git a/micro-async-data-loader/src/test/java/app/loader/scheduled/off/com/oath/micro/server/CouchbaseResource.java b/micro-async-data-loader/src/test/java/app/loader/scheduled/off/com/oath/micro/server/CouchbaseResource.java new file mode 100644 index 000000000..955dc8ead --- /dev/null +++ b/micro-async-data-loader/src/test/java/app/loader/scheduled/off/com/oath/micro/server/CouchbaseResource.java @@ -0,0 +1,64 @@ +package app.loader.scheduled.off.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import cyclops.collections.immutable.LinkedListX; +import cyclops.control.Maybe; +import org.springframework.beans.factory.annotation.Autowired; + + +import com.oath.micro.server.auto.discovery.Rest; +import com.oath.micro.server.distributed.DistributedMap; +import com.oath.micro.server.events.SystemData; +import com.google.common.eventbus.EventBus; +import com.google.common.eventbus.Subscribe; + +@Path("/couchbase") +@Rest +public class CouchbaseResource { + + private final DistributedMap client; + private volatile LinkedListX dataLoads = LinkedListX.empty(); + + @Autowired + public CouchbaseResource(DistributedMap client, EventBus bus) { + this.client = client; + bus.register(this); + } + + @Subscribe + public synchronized void events(SystemData event) { + dataLoads = dataLoads.plus(event); + + } + + @GET + @Path("/loading-events") + @Produces("application/json") + public synchronized LinkedListX loadingEvents() { + return dataLoads; + } + + @GET + @Path("/maybe") + @Produces("application/json") + public Maybe maybe() { + return Maybe.just("hello-world"); + } + + @GET + @Path("/get") + public String bucket() { + return client.get("hello") + .toString(); + } + + @GET + @Path("/put") + public String put() { + client.put("hello", "world"); + return "added"; + } +} diff --git a/micro-async-data-loader/src/test/java/app/loader/scheduled/off/com/oath/micro/server/CouchbaseRunnerTest.java b/micro-async-data-loader/src/test/java/app/loader/scheduled/off/com/oath/micro/server/CouchbaseRunnerTest.java new file mode 100644 index 000000000..4b6774915 --- /dev/null +++ b/micro-async-data-loader/src/test/java/app/loader/scheduled/off/com/oath/micro/server/CouchbaseRunnerTest.java @@ -0,0 +1,66 @@ +package app.loader.scheduled.off.com.oath.micro.server; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; + +import java.util.List; +import java.util.concurrent.ExecutionException; + +import org.couchbase.mock.CouchbaseMock; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.module.ConfigurableModule; +import com.oath.micro.server.rest.jackson.JacksonUtil; +import com.oath.micro.server.testing.RestAgent; + +@Microserver(properties = { "couchbaseServers", "http://localhost:8091/pools", "couchbasePassword", "", + "couchbaseBucket", "beer-sample", "async.data.schedular.cron.loader", "* * * * * ?", + "async.data.schedular.cron.cleaner", "* * * * * ?" }) +public class CouchbaseRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + + @Before + public void startServer() { + try { + // couchbase already running? + rest.get("http://localhost:8091/pools"); + } catch (Exception e) { + // start mock couchbase + CouchbaseMock.main(new String[] { "-S" }); + } + server = new MicroserverApp( + ConfigurableModule.builder() + .context("simple-app") + .build()); + + server.start(); + + } + + @After + public void stopServer() { + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException { + rest.get("http://localhost:8080/simple-app/couchbase/put"); + assertThat(rest.get("http://localhost:8080/simple-app/couchbase/get"), containsString("world")); + + Thread.sleep(2000); + String json = rest.getJson("http://localhost:8080/simple-app/couchbase/loading-events"); + List list = JacksonUtil.convertFromJson(json, List.class); + System.out.println(list); + assertTrue(list.size() == 0); + + } + +} diff --git a/micro-async-data-loader/src/test/java/app/loader/scheduled/off/com/oath/micro/server/TurnOff.java b/micro-async-data-loader/src/test/java/app/loader/scheduled/off/com/oath/micro/server/TurnOff.java new file mode 100644 index 000000000..3d74501a9 --- /dev/null +++ b/micro-async-data-loader/src/test/java/app/loader/scheduled/off/com/oath/micro/server/TurnOff.java @@ -0,0 +1,15 @@ +package app.loader.scheduled.off.com.oath.micro.server; + +import org.springframework.stereotype.Component; + +import com.oath.micro.server.async.data.loader.ConditionallyLoad; + +@Component +public class TurnOff implements ConditionallyLoad { + + @Override + public boolean shouldLoad() { + return false; + } + +} diff --git a/micro-async-data-loader/src/test/java/com/aol/micro/server/testing/RestAgent.java b/micro-async-data-loader/src/test/java/com/aol/micro/server/testing/RestAgent.java deleted file mode 100644 index ce204f810..000000000 --- a/micro-async-data-loader/src/test/java/com/aol/micro/server/testing/RestAgent.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.aol.micro.server.testing; - -import java.util.List; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.Invocation.Builder; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; - -import com.aol.micro.server.rest.jackson.JacksonUtil; - -public class RestAgent { - - - public String getJson(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.get(String.class); - - } - - public String get(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.TEXT_PLAIN); - - return request.get(String.class); - - } - - public T post(String url, Object payload,Class type) { - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); - } - - -} diff --git a/micro-async-data-loader/src/test/java/com/oath/micro/server/testing/RestAgent.java b/micro-async-data-loader/src/test/java/com/oath/micro/server/testing/RestAgent.java new file mode 100644 index 000000000..b2b86303e --- /dev/null +++ b/micro-async-data-loader/src/test/java/com/oath/micro/server/testing/RestAgent.java @@ -0,0 +1,53 @@ +package com.oath.micro.server.testing; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.Invocation.Builder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; + +import com.oath.micro.server.rest.jackson.JacksonUtil; + +public class RestAgent { + + + public String getJson(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.get(String.class); + + } + + public String get(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.TEXT_PLAIN); + + return request.get(String.class); + + } + + public T post(String url, Object payload,Class type) { + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); + } + + +} diff --git a/micro-async-data-writer/src/main/java/com/aol/micro/server/async/data/cleaner/ConditionallyClean.java b/micro-async-data-writer/src/main/java/com/aol/micro/server/async/data/cleaner/ConditionallyClean.java deleted file mode 100644 index 291e5a895..000000000 --- a/micro-async-data-writer/src/main/java/com/aol/micro/server/async/data/cleaner/ConditionallyClean.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.aol.micro.server.async.data.cleaner; - -public interface ConditionallyClean { - - public boolean shouldClean(); -} diff --git a/micro-async-data-writer/src/main/java/com/aol/micro/server/async/data/writer/plugin/AsyncDataWriterPlugin.java b/micro-async-data-writer/src/main/java/com/aol/micro/server/async/data/writer/plugin/AsyncDataWriterPlugin.java deleted file mode 100644 index e4379eb7b..000000000 --- a/micro-async-data-writer/src/main/java/com/aol/micro/server/async/data/writer/plugin/AsyncDataWriterPlugin.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.aol.micro.server.async.data.writer.plugin; - -import java.util.Set; - - -import com.aol.micro.server.Plugin; -import com.aol.micro.server.async.data.cleaner.ConfigureSchedulingAsyncDataWriter; -import com.aol.micro.server.async.data.writer.ConfigureDataWriter; -import cyclops.collections.mutable.SetX; - -public class AsyncDataWriterPlugin implements Plugin { - - @Override - public Set springClasses() { - return SetX.of(ConfigureSchedulingAsyncDataWriter.class, ConfigureDataWriter.class); - } - -} diff --git a/micro-async-data-writer/src/main/java/com/aol/micro/server/async/data/cleaner/CleanerSchedular.java b/micro-async-data-writer/src/main/java/com/oath/micro/server/async/data/cleaner/CleanerSchedular.java similarity index 94% rename from micro-async-data-writer/src/main/java/com/aol/micro/server/async/data/cleaner/CleanerSchedular.java rename to micro-async-data-writer/src/main/java/com/oath/micro/server/async/data/cleaner/CleanerSchedular.java index d886918bf..d406ebe30 100644 --- a/micro-async-data-writer/src/main/java/com/aol/micro/server/async/data/cleaner/CleanerSchedular.java +++ b/micro-async-data-writer/src/main/java/com/oath/micro/server/async/data/cleaner/CleanerSchedular.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.async.data.cleaner; +package com.oath.micro.server.async.data.cleaner; import java.util.concurrent.ScheduledExecutorService; diff --git a/micro-async-data-writer/src/main/java/com/oath/micro/server/async/data/cleaner/ConditionallyClean.java b/micro-async-data-writer/src/main/java/com/oath/micro/server/async/data/cleaner/ConditionallyClean.java new file mode 100644 index 000000000..2890330e8 --- /dev/null +++ b/micro-async-data-writer/src/main/java/com/oath/micro/server/async/data/cleaner/ConditionallyClean.java @@ -0,0 +1,6 @@ +package com.oath.micro.server.async.data.cleaner; + +public interface ConditionallyClean { + + public boolean shouldClean(); +} diff --git a/micro-async-data-writer/src/main/java/com/aol/micro/server/async/data/cleaner/ConfigureSchedulingAsyncDataWriter.java b/micro-async-data-writer/src/main/java/com/oath/micro/server/async/data/cleaner/ConfigureSchedulingAsyncDataWriter.java similarity index 95% rename from micro-async-data-writer/src/main/java/com/aol/micro/server/async/data/cleaner/ConfigureSchedulingAsyncDataWriter.java rename to micro-async-data-writer/src/main/java/com/oath/micro/server/async/data/cleaner/ConfigureSchedulingAsyncDataWriter.java index 68fc49b78..464871f47 100644 --- a/micro-async-data-writer/src/main/java/com/aol/micro/server/async/data/cleaner/ConfigureSchedulingAsyncDataWriter.java +++ b/micro-async-data-writer/src/main/java/com/oath/micro/server/async/data/cleaner/ConfigureSchedulingAsyncDataWriter.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.async.data.cleaner; +package com.oath.micro.server.async.data.cleaner; import java.util.List; import java.util.concurrent.Executors; @@ -12,7 +12,7 @@ import org.springframework.context.annotation.Configuration; -import com.aol.micro.server.manifest.ManifestComparator; +import com.oath.micro.server.manifest.ManifestComparator; import com.google.common.eventbus.EventBus; @Configuration diff --git a/micro-async-data-writer/src/main/java/com/aol/micro/server/async/data/cleaner/DataCleaner.java b/micro-async-data-writer/src/main/java/com/oath/micro/server/async/data/cleaner/DataCleaner.java similarity index 86% rename from micro-async-data-writer/src/main/java/com/aol/micro/server/async/data/cleaner/DataCleaner.java rename to micro-async-data-writer/src/main/java/com/oath/micro/server/async/data/cleaner/DataCleaner.java index a249ea3a4..6f6b78d30 100644 --- a/micro-async-data-writer/src/main/java/com/aol/micro/server/async/data/cleaner/DataCleaner.java +++ b/micro-async-data-writer/src/main/java/com/oath/micro/server/async/data/cleaner/DataCleaner.java @@ -1,13 +1,13 @@ -package com.aol.micro.server.async.data.cleaner; +package com.oath.micro.server.async.data.cleaner; import java.util.Random; import java.util.function.Supplier; -import com.aol.micro.server.events.ScheduledJob; -import com.aol.micro.server.events.SystemData; -import com.aol.micro.server.manifest.ManifestComparator; -import com.aol.micro.server.utility.HashMapBuilder; +import com.oath.micro.server.events.ScheduledJob; +import com.oath.micro.server.events.SystemData; +import com.oath.micro.server.manifest.ManifestComparator; +import com.oath.micro.server.utility.HashMapBuilder; import cyclops.collections.mutable.MapX; import lombok.AllArgsConstructor; diff --git a/micro-async-data-writer/src/main/java/com/aol/micro/server/async/data/writer/AsyncDataWriter.java b/micro-async-data-writer/src/main/java/com/oath/micro/server/async/data/writer/AsyncDataWriter.java similarity index 95% rename from micro-async-data-writer/src/main/java/com/aol/micro/server/async/data/writer/AsyncDataWriter.java rename to micro-async-data-writer/src/main/java/com/oath/micro/server/async/data/writer/AsyncDataWriter.java index a554f00c5..b937494a6 100644 --- a/micro-async-data-writer/src/main/java/com/aol/micro/server/async/data/writer/AsyncDataWriter.java +++ b/micro-async-data-writer/src/main/java/com/oath/micro/server/async/data/writer/AsyncDataWriter.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.async.data.writer; +package com.oath.micro.server.async.data.writer; import java.util.Random; import java.util.concurrent.Executor; @@ -9,9 +9,9 @@ import cyclops.data.tuple.Tuple; -import com.aol.micro.server.events.SystemData; -import com.aol.micro.server.manifest.ManifestComparator; -import com.aol.micro.server.utility.HashMapBuilder; +import com.oath.micro.server.events.SystemData; +import com.oath.micro.server.manifest.ManifestComparator; +import com.oath.micro.server.utility.HashMapBuilder; import com.google.common.eventbus.EventBus; import lombok.AllArgsConstructor; diff --git a/micro-async-data-writer/src/main/java/com/aol/micro/server/async/data/writer/ConfigureDataWriter.java b/micro-async-data-writer/src/main/java/com/oath/micro/server/async/data/writer/ConfigureDataWriter.java similarity index 95% rename from micro-async-data-writer/src/main/java/com/aol/micro/server/async/data/writer/ConfigureDataWriter.java rename to micro-async-data-writer/src/main/java/com/oath/micro/server/async/data/writer/ConfigureDataWriter.java index 5c038c9c8..95bb53be5 100644 --- a/micro-async-data-writer/src/main/java/com/aol/micro/server/async/data/writer/ConfigureDataWriter.java +++ b/micro-async-data-writer/src/main/java/com/oath/micro/server/async/data/writer/ConfigureDataWriter.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.async.data.writer; +package com.oath.micro.server.async.data.writer; import java.util.List; import java.util.concurrent.Executor; @@ -13,7 +13,7 @@ import org.springframework.context.annotation.Configuration; -import com.aol.micro.server.manifest.ManifestComparator; +import com.oath.micro.server.manifest.ManifestComparator; import com.google.common.eventbus.EventBus; @Configuration diff --git a/micro-async-data-writer/src/main/java/com/aol/micro/server/async/data/writer/DataWriter.java b/micro-async-data-writer/src/main/java/com/oath/micro/server/async/data/writer/DataWriter.java similarity index 78% rename from micro-async-data-writer/src/main/java/com/aol/micro/server/async/data/writer/DataWriter.java rename to micro-async-data-writer/src/main/java/com/oath/micro/server/async/data/writer/DataWriter.java index 2222dcc99..2d1e901f7 100644 --- a/micro-async-data-writer/src/main/java/com/aol/micro/server/async/data/writer/DataWriter.java +++ b/micro-async-data-writer/src/main/java/com/oath/micro/server/async/data/writer/DataWriter.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.async.data.writer; +package com.oath.micro.server.async.data.writer; import cyclops.async.Future; diff --git a/micro-async-data-writer/src/main/java/com/aol/micro/server/async/data/writer/MultiDataWriter.java b/micro-async-data-writer/src/main/java/com/oath/micro/server/async/data/writer/MultiDataWriter.java similarity index 95% rename from micro-async-data-writer/src/main/java/com/aol/micro/server/async/data/writer/MultiDataWriter.java rename to micro-async-data-writer/src/main/java/com/oath/micro/server/async/data/writer/MultiDataWriter.java index f9b1c1217..590b6fcf8 100644 --- a/micro-async-data-writer/src/main/java/com/aol/micro/server/async/data/writer/MultiDataWriter.java +++ b/micro-async-data-writer/src/main/java/com/oath/micro/server/async/data/writer/MultiDataWriter.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.async.data.writer; +package com.oath.micro.server.async.data.writer; diff --git a/micro-async-data-writer/src/main/java/com/oath/micro/server/async/data/writer/plugin/AsyncDataWriterPlugin.java b/micro-async-data-writer/src/main/java/com/oath/micro/server/async/data/writer/plugin/AsyncDataWriterPlugin.java new file mode 100644 index 000000000..55d605c78 --- /dev/null +++ b/micro-async-data-writer/src/main/java/com/oath/micro/server/async/data/writer/plugin/AsyncDataWriterPlugin.java @@ -0,0 +1,18 @@ +package com.oath.micro.server.async.data.writer.plugin; + +import java.util.Set; + + +import com.oath.micro.server.Plugin; +import com.oath.micro.server.async.data.cleaner.ConfigureSchedulingAsyncDataWriter; +import com.oath.micro.server.async.data.writer.ConfigureDataWriter; +import cyclops.collections.mutable.SetX; + +public class AsyncDataWriterPlugin implements Plugin { + + @Override + public Set springClasses() { + return SetX.of(ConfigureSchedulingAsyncDataWriter.class, ConfigureDataWriter.class); + } + +} diff --git a/micro-async-data-writer/src/main/resources/META-INF/services/com.aol.micro.server.Plugin b/micro-async-data-writer/src/main/resources/META-INF/services/com.aol.micro.server.Plugin deleted file mode 100644 index fc472f9ae..000000000 --- a/micro-async-data-writer/src/main/resources/META-INF/services/com.aol.micro.server.Plugin +++ /dev/null @@ -1 +0,0 @@ -com.aol.micro.server.async.data.writer.plugin.AsyncDataWriterPlugin \ No newline at end of file diff --git a/micro-async-data-writer/src/main/resources/META-INF/services/com.oath.micro.server.Plugin b/micro-async-data-writer/src/main/resources/META-INF/services/com.oath.micro.server.Plugin new file mode 100644 index 000000000..a05010df2 --- /dev/null +++ b/micro-async-data-writer/src/main/resources/META-INF/services/com.oath.micro.server.Plugin @@ -0,0 +1 @@ +com.oath.micro.server.async.data.writer.plugin.AsyncDataWriterPlugin \ No newline at end of file diff --git a/micro-async-data-writer/src/test/java/app/cleaner/off/scheduled/com/aol/micro/server/CouchbaseResource.java b/micro-async-data-writer/src/test/java/app/cleaner/off/scheduled/com/aol/micro/server/CouchbaseResource.java deleted file mode 100644 index 9d30b5aaf..000000000 --- a/micro-async-data-writer/src/test/java/app/cleaner/off/scheduled/com/aol/micro/server/CouchbaseResource.java +++ /dev/null @@ -1,64 +0,0 @@ -package app.cleaner.off.scheduled.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import cyclops.collections.immutable.LinkedListX; -import cyclops.control.Maybe; -import org.springframework.beans.factory.annotation.Autowired; - - -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.distributed.DistributedMap; -import com.aol.micro.server.events.SystemData; -import com.google.common.eventbus.EventBus; -import com.google.common.eventbus.Subscribe; - -@Path("/couchbase") -@Rest -public class CouchbaseResource { - - private final DistributedMap client; - - private volatile LinkedListX dataCleans = LinkedListX.empty(); - - @Autowired - public CouchbaseResource(DistributedMap client, EventBus bus) { - this.client = client; - bus.register(this); - } - - @Subscribe - public synchronized void events(SystemData event) { - dataCleans = dataCleans.plus(event); - } - - @GET - @Path("/cleaning-events") - @Produces("application/json") - public synchronized LinkedListX cleaningEvents() { - return dataCleans; - } - - @GET - @Path("/maybe") - @Produces("application/json") - public Maybe maybe() { - return Maybe.just("hello-world"); - } - - @GET - @Path("/get") - public String bucket() { - return client.get("hello") - .toString(); - } - - @GET - @Path("/put") - public String put() { - client.put("hello", "world"); - return "added"; - } -} diff --git a/micro-async-data-writer/src/test/java/app/cleaner/off/scheduled/com/aol/micro/server/CouchbaseRunnerTest.java b/micro-async-data-writer/src/test/java/app/cleaner/off/scheduled/com/aol/micro/server/CouchbaseRunnerTest.java deleted file mode 100644 index 86df3f79b..000000000 --- a/micro-async-data-writer/src/test/java/app/cleaner/off/scheduled/com/aol/micro/server/CouchbaseRunnerTest.java +++ /dev/null @@ -1,67 +0,0 @@ -package app.cleaner.off.scheduled.com.aol.micro.server; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - -import java.util.List; -import java.util.concurrent.ExecutionException; - -import org.couchbase.mock.CouchbaseMock; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.rest.jackson.JacksonUtil; -import com.aol.micro.server.testing.RestAgent; - -@Microserver(properties = { "couchbaseServers", "http://localhost:8091/pools", "couchbasePassword", "", - "couchbaseBucket", "beer-sample", "async.data.schedular.cron.loader", "* * * * * ?", - "async.data.schedular.cron.cleaner", "* * * * * ?" }) -public class CouchbaseRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - - @Before - public void startServer() { - try { - // couchbase already running? - rest.get("http://localhost:8091/pools"); - } catch (Exception e) { - // start mock couchbase - CouchbaseMock.main(new String[] { "-S" }); - } - server = new MicroserverApp( - ConfigurableModule.builder() - .context("simple-app") - .build()); - - server.start(); - - } - - @After - public void stopServer() { - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException { - rest.get("http://localhost:8080/simple-app/couchbase/put"); - assertThat(rest.get("http://localhost:8080/simple-app/couchbase/get"), containsString("world")); - - Thread.sleep(2000); - - String json = rest.getJson("http://localhost:8080/simple-app/couchbase/cleaning-events"); - List list = JacksonUtil.convertFromJson(json, List.class); - System.out.println(list); - assertTrue(list.size() == 0); - - } - -} diff --git a/micro-async-data-writer/src/test/java/app/cleaner/off/scheduled/com/aol/micro/server/TurnOff.java b/micro-async-data-writer/src/test/java/app/cleaner/off/scheduled/com/aol/micro/server/TurnOff.java deleted file mode 100644 index 2266f916e..000000000 --- a/micro-async-data-writer/src/test/java/app/cleaner/off/scheduled/com/aol/micro/server/TurnOff.java +++ /dev/null @@ -1,16 +0,0 @@ -package app.cleaner.off.scheduled.com.aol.micro.server; - -import org.springframework.stereotype.Component; - -import com.aol.micro.server.async.data.cleaner.ConditionallyClean; - -@Component -public class TurnOff implements ConditionallyClean { - - @Override - public boolean shouldClean() { - - return false; - } - -} diff --git a/micro-async-data-writer/src/test/java/app/cleaner/off/scheduled/com/oath/micro/server/CouchbaseResource.java b/micro-async-data-writer/src/test/java/app/cleaner/off/scheduled/com/oath/micro/server/CouchbaseResource.java new file mode 100644 index 000000000..c058fb571 --- /dev/null +++ b/micro-async-data-writer/src/test/java/app/cleaner/off/scheduled/com/oath/micro/server/CouchbaseResource.java @@ -0,0 +1,64 @@ +package app.cleaner.off.scheduled.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import cyclops.collections.immutable.LinkedListX; +import cyclops.control.Maybe; +import org.springframework.beans.factory.annotation.Autowired; + + +import com.oath.micro.server.auto.discovery.Rest; +import com.oath.micro.server.distributed.DistributedMap; +import com.oath.micro.server.events.SystemData; +import com.google.common.eventbus.EventBus; +import com.google.common.eventbus.Subscribe; + +@Path("/couchbase") +@Rest +public class CouchbaseResource { + + private final DistributedMap client; + + private volatile LinkedListX dataCleans = LinkedListX.empty(); + + @Autowired + public CouchbaseResource(DistributedMap client, EventBus bus) { + this.client = client; + bus.register(this); + } + + @Subscribe + public synchronized void events(SystemData event) { + dataCleans = dataCleans.plus(event); + } + + @GET + @Path("/cleaning-events") + @Produces("application/json") + public synchronized LinkedListX cleaningEvents() { + return dataCleans; + } + + @GET + @Path("/maybe") + @Produces("application/json") + public Maybe maybe() { + return Maybe.just("hello-world"); + } + + @GET + @Path("/get") + public String bucket() { + return client.get("hello") + .toString(); + } + + @GET + @Path("/put") + public String put() { + client.put("hello", "world"); + return "added"; + } +} diff --git a/micro-async-data-writer/src/test/java/app/cleaner/off/scheduled/com/oath/micro/server/CouchbaseRunnerTest.java b/micro-async-data-writer/src/test/java/app/cleaner/off/scheduled/com/oath/micro/server/CouchbaseRunnerTest.java new file mode 100644 index 000000000..b60689ded --- /dev/null +++ b/micro-async-data-writer/src/test/java/app/cleaner/off/scheduled/com/oath/micro/server/CouchbaseRunnerTest.java @@ -0,0 +1,67 @@ +package app.cleaner.off.scheduled.com.oath.micro.server; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; + +import java.util.List; +import java.util.concurrent.ExecutionException; + +import org.couchbase.mock.CouchbaseMock; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.module.ConfigurableModule; +import com.oath.micro.server.rest.jackson.JacksonUtil; +import com.oath.micro.server.testing.RestAgent; + +@Microserver(properties = { "couchbaseServers", "http://localhost:8091/pools", "couchbasePassword", "", + "couchbaseBucket", "beer-sample", "async.data.schedular.cron.loader", "* * * * * ?", + "async.data.schedular.cron.cleaner", "* * * * * ?" }) +public class CouchbaseRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + + @Before + public void startServer() { + try { + // couchbase already running? + rest.get("http://localhost:8091/pools"); + } catch (Exception e) { + // start mock couchbase + CouchbaseMock.main(new String[] { "-S" }); + } + server = new MicroserverApp( + ConfigurableModule.builder() + .context("simple-app") + .build()); + + server.start(); + + } + + @After + public void stopServer() { + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException { + rest.get("http://localhost:8080/simple-app/couchbase/put"); + assertThat(rest.get("http://localhost:8080/simple-app/couchbase/get"), containsString("world")); + + Thread.sleep(2000); + + String json = rest.getJson("http://localhost:8080/simple-app/couchbase/cleaning-events"); + List list = JacksonUtil.convertFromJson(json, List.class); + System.out.println(list); + assertTrue(list.size() == 0); + + } + +} diff --git a/micro-async-data-writer/src/test/java/app/cleaner/off/scheduled/com/oath/micro/server/TurnOff.java b/micro-async-data-writer/src/test/java/app/cleaner/off/scheduled/com/oath/micro/server/TurnOff.java new file mode 100644 index 000000000..c387db307 --- /dev/null +++ b/micro-async-data-writer/src/test/java/app/cleaner/off/scheduled/com/oath/micro/server/TurnOff.java @@ -0,0 +1,16 @@ +package app.cleaner.off.scheduled.com.oath.micro.server; + +import org.springframework.stereotype.Component; + +import com.oath.micro.server.async.data.cleaner.ConditionallyClean; + +@Component +public class TurnOff implements ConditionallyClean { + + @Override + public boolean shouldClean() { + + return false; + } + +} diff --git a/micro-async-data-writer/src/test/java/app/cleaner/scheduled/com/aol/micro/server/CouchbaseResource.java b/micro-async-data-writer/src/test/java/app/cleaner/scheduled/com/aol/micro/server/CouchbaseResource.java deleted file mode 100644 index cc0c3008e..000000000 --- a/micro-async-data-writer/src/test/java/app/cleaner/scheduled/com/aol/micro/server/CouchbaseResource.java +++ /dev/null @@ -1,64 +0,0 @@ -package app.cleaner.scheduled.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import cyclops.collections.immutable.LinkedListX; -import cyclops.control.Maybe; -import org.springframework.beans.factory.annotation.Autowired; - - -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.distributed.DistributedMap; -import com.aol.micro.server.events.SystemData; -import com.google.common.eventbus.EventBus; -import com.google.common.eventbus.Subscribe; - -@Path("/couchbase") -@Rest -public class CouchbaseResource { - - private final DistributedMap client; - - private volatile LinkedListX dataCleans = LinkedListX.empty(); - - @Autowired - public CouchbaseResource(DistributedMap client, EventBus bus) { - this.client = client; - bus.register(this); - } - - @Subscribe - public synchronized void events(SystemData event) { - dataCleans = dataCleans.plus(event); - } - - @GET - @Path("/cleaning-events") - @Produces("application/json") - public synchronized LinkedListX cleaningEvents() { - return dataCleans; - } - - @GET - @Path("/maybe") - @Produces("application/json") - public Maybe maybe() { - return Maybe.just("hello-world"); - } - - @GET - @Path("/get") - public String bucket() { - return client.get("hello") - .toString(); - } - - @GET - @Path("/put") - public String put() { - client.put("hello", "world"); - return "added"; - } -} diff --git a/micro-async-data-writer/src/test/java/app/cleaner/scheduled/com/aol/micro/server/CouchbaseRunnerTest.java b/micro-async-data-writer/src/test/java/app/cleaner/scheduled/com/aol/micro/server/CouchbaseRunnerTest.java deleted file mode 100644 index 8baa70cfe..000000000 --- a/micro-async-data-writer/src/test/java/app/cleaner/scheduled/com/aol/micro/server/CouchbaseRunnerTest.java +++ /dev/null @@ -1,67 +0,0 @@ -package app.cleaner.scheduled.com.aol.micro.server; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - -import java.util.List; -import java.util.concurrent.ExecutionException; - -import org.couchbase.mock.CouchbaseMock; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.rest.jackson.JacksonUtil; -import com.aol.micro.server.testing.RestAgent; - -@Microserver(properties = { "couchbaseServers", "http://localhost:8091/pools", "couchbasePassword", "", - "couchbaseBucket", "beer-sample", "async.data.schedular.cron.loader", "* * * * * ?", - "async.data.schedular.cron.cleaner", "* * * * * ?" }) -public class CouchbaseRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - - @Before - public void startServer() { - try { - // couchbase already running? - rest.get("http://localhost:8091/pools"); - } catch (Exception e) { - // start mock couchbase - CouchbaseMock.main(new String[] { "-S" }); - } - server = new MicroserverApp( - ConfigurableModule.builder() - .context("simple-app") - .build()); - - server.start(); - - } - - @After - public void stopServer() { - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException { - rest.get("http://localhost:8080/simple-app/couchbase/put"); - assertThat(rest.get("http://localhost:8080/simple-app/couchbase/get"), containsString("world")); - - Thread.sleep(2000); - - String json = rest.getJson("http://localhost:8080/simple-app/couchbase/cleaning-events"); - List list = JacksonUtil.convertFromJson(json, List.class); - System.out.println(list); - assertTrue(list.size() > 0); - - } - -} diff --git a/micro-async-data-writer/src/test/java/app/cleaner/scheduled/com/oath/micro/server/CouchbaseResource.java b/micro-async-data-writer/src/test/java/app/cleaner/scheduled/com/oath/micro/server/CouchbaseResource.java new file mode 100644 index 000000000..68a01d2eb --- /dev/null +++ b/micro-async-data-writer/src/test/java/app/cleaner/scheduled/com/oath/micro/server/CouchbaseResource.java @@ -0,0 +1,64 @@ +package app.cleaner.scheduled.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import cyclops.collections.immutable.LinkedListX; +import cyclops.control.Maybe; +import org.springframework.beans.factory.annotation.Autowired; + + +import com.oath.micro.server.auto.discovery.Rest; +import com.oath.micro.server.distributed.DistributedMap; +import com.oath.micro.server.events.SystemData; +import com.google.common.eventbus.EventBus; +import com.google.common.eventbus.Subscribe; + +@Path("/couchbase") +@Rest +public class CouchbaseResource { + + private final DistributedMap client; + + private volatile LinkedListX dataCleans = LinkedListX.empty(); + + @Autowired + public CouchbaseResource(DistributedMap client, EventBus bus) { + this.client = client; + bus.register(this); + } + + @Subscribe + public synchronized void events(SystemData event) { + dataCleans = dataCleans.plus(event); + } + + @GET + @Path("/cleaning-events") + @Produces("application/json") + public synchronized LinkedListX cleaningEvents() { + return dataCleans; + } + + @GET + @Path("/maybe") + @Produces("application/json") + public Maybe maybe() { + return Maybe.just("hello-world"); + } + + @GET + @Path("/get") + public String bucket() { + return client.get("hello") + .toString(); + } + + @GET + @Path("/put") + public String put() { + client.put("hello", "world"); + return "added"; + } +} diff --git a/micro-async-data-writer/src/test/java/app/cleaner/scheduled/com/oath/micro/server/CouchbaseRunnerTest.java b/micro-async-data-writer/src/test/java/app/cleaner/scheduled/com/oath/micro/server/CouchbaseRunnerTest.java new file mode 100644 index 000000000..7a898fd53 --- /dev/null +++ b/micro-async-data-writer/src/test/java/app/cleaner/scheduled/com/oath/micro/server/CouchbaseRunnerTest.java @@ -0,0 +1,67 @@ +package app.cleaner.scheduled.com.oath.micro.server; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; + +import java.util.List; +import java.util.concurrent.ExecutionException; + +import org.couchbase.mock.CouchbaseMock; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.module.ConfigurableModule; +import com.oath.micro.server.rest.jackson.JacksonUtil; +import com.oath.micro.server.testing.RestAgent; + +@Microserver(properties = { "couchbaseServers", "http://localhost:8091/pools", "couchbasePassword", "", + "couchbaseBucket", "beer-sample", "async.data.schedular.cron.loader", "* * * * * ?", + "async.data.schedular.cron.cleaner", "* * * * * ?" }) +public class CouchbaseRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + + @Before + public void startServer() { + try { + // couchbase already running? + rest.get("http://localhost:8091/pools"); + } catch (Exception e) { + // start mock couchbase + CouchbaseMock.main(new String[] { "-S" }); + } + server = new MicroserverApp( + ConfigurableModule.builder() + .context("simple-app") + .build()); + + server.start(); + + } + + @After + public void stopServer() { + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException { + rest.get("http://localhost:8080/simple-app/couchbase/put"); + assertThat(rest.get("http://localhost:8080/simple-app/couchbase/get"), containsString("world")); + + Thread.sleep(2000); + + String json = rest.getJson("http://localhost:8080/simple-app/couchbase/cleaning-events"); + List list = JacksonUtil.convertFromJson(json, List.class); + System.out.println(list); + assertTrue(list.size() > 0); + + } + +} diff --git a/micro-async-data-writer/src/test/java/app/writer/configured/com/aol/micro/server/ManifestComparatorResource.java b/micro-async-data-writer/src/test/java/app/writer/configured/com/aol/micro/server/ManifestComparatorResource.java deleted file mode 100644 index 1e935e5b1..000000000 --- a/micro-async-data-writer/src/test/java/app/writer/configured/com/aol/micro/server/ManifestComparatorResource.java +++ /dev/null @@ -1,48 +0,0 @@ -package app.writer.configured.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; - -import org.springframework.beans.factory.annotation.Autowired; - -import com.aol.micro.server.async.data.writer.AsyncDataWriter; -import com.aol.micro.server.auto.discovery.Rest; - -@Path("/comparator") -@Rest -public class ManifestComparatorResource { - - private volatile int count = 1; - private final AsyncDataWriter comparator; - - @Autowired - public ManifestComparatorResource(AsyncDataWriter comparator) { - this.comparator = comparator; - } - - @GET - @Path("/increment") - public String bucket() { - comparator.saveAndIncrement("hello" + (count++)) - .get(); - return "incremented"; - } - - @GET - @Path("/get") - public String get() { - - return comparator.loadAndGet() - .visit(s->s,e->"Error loading " + e.getMessage()); - - } - - - @GET - @Path("/check") - public String check() { - return "" + !comparator.isOutOfDate() - .getOrElse(null); - - } -} diff --git a/micro-async-data-writer/src/test/java/app/writer/configured/com/aol/micro/server/ManifestComparatorRunnerTest.java b/micro-async-data-writer/src/test/java/app/writer/configured/com/aol/micro/server/ManifestComparatorRunnerTest.java deleted file mode 100644 index e0961e5b4..000000000 --- a/micro-async-data-writer/src/test/java/app/writer/configured/com/aol/micro/server/ManifestComparatorRunnerTest.java +++ /dev/null @@ -1,62 +0,0 @@ -package app.writer.configured.com.aol.micro.server; - -import static org.hamcrest.CoreMatchers.equalTo; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import org.couchbase.mock.CouchbaseMock; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.testing.RestAgent; - -@Microserver(properties = { "couchbaseServers", "http://localhost:8091/pools", "couchbasePassword", "", - "couchbaseBucket", "beer-sample", "couchbase.manifest.comparison.key", "test-key" }) -public class ManifestComparatorRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - - @Before - public void startServer() { - try { - // couchbase already running? - rest.get("http://localhost:8091/pools"); - } catch (Exception e) { - // start mock couchbase - CouchbaseMock.main(new String[] { "-S" }); - } - server = new MicroserverApp( - () -> "simple-app"); - - server.start(); - - } - - @After - public void stopServer() { - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException { - rest.get("http://localhost:8080/simple-app/comparator/increment"); - - assertThat(rest.get("http://localhost:8080/simple-app/comparator/check"), equalTo("true")); - assertThat(rest.get("http://localhost:8080/simple-app/comparator/get"), equalTo("hello1")); - rest.get("http://localhost:8080/simple-app/comparator/increment"); - assertThat(rest.get("http://localhost:8080/simple-app/comparator/get"), equalTo("hello2")); - - rest.get("http://localhost:8080/simple-app/comparator2/increment"); - - assertThat(rest.get("http://localhost:8080/simple-app/comparator/check"), equalTo("false")); - assertThat(rest.get("http://localhost:8080/simple-app/comparator/get"), equalTo("hellob")); - - } - -} diff --git a/micro-async-data-writer/src/test/java/app/writer/configured/com/aol/micro/server/SecondComparatorResource.java b/micro-async-data-writer/src/test/java/app/writer/configured/com/aol/micro/server/SecondComparatorResource.java deleted file mode 100644 index 8b5a1676f..000000000 --- a/micro-async-data-writer/src/test/java/app/writer/configured/com/aol/micro/server/SecondComparatorResource.java +++ /dev/null @@ -1,44 +0,0 @@ -package app.writer.configured.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; - -import org.springframework.beans.factory.annotation.Autowired; - -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.manifest.ManifestComparator; - -@Path("/comparator2") -@Rest -public class SecondComparatorResource { - - private final ManifestComparator comparator; - - @Autowired - public SecondComparatorResource(ManifestComparator comparator) { - this.comparator = comparator.withKey("test-key"); - } - - @GET - @Path("/increment") - public String bucket() { - comparator.saveAndIncrement("hellob"); - return "increment"; - } - - @GET - @Path("/get") - public String get() { - comparator.load(); - return comparator.getData() - .toString(); - - } - - @GET - @Path("/check") - public String check() { - return "" + !comparator.isOutOfDate(); - - } -} \ No newline at end of file diff --git a/micro-async-data-writer/src/test/java/app/writer/configured/com/oath/micro/server/ManifestComparatorResource.java b/micro-async-data-writer/src/test/java/app/writer/configured/com/oath/micro/server/ManifestComparatorResource.java new file mode 100644 index 000000000..754dff685 --- /dev/null +++ b/micro-async-data-writer/src/test/java/app/writer/configured/com/oath/micro/server/ManifestComparatorResource.java @@ -0,0 +1,48 @@ +package app.writer.configured.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +import org.springframework.beans.factory.annotation.Autowired; + +import com.oath.micro.server.async.data.writer.AsyncDataWriter; +import com.oath.micro.server.auto.discovery.Rest; + +@Path("/comparator") +@Rest +public class ManifestComparatorResource { + + private volatile int count = 1; + private final AsyncDataWriter comparator; + + @Autowired + public ManifestComparatorResource(AsyncDataWriter comparator) { + this.comparator = comparator; + } + + @GET + @Path("/increment") + public String bucket() { + comparator.saveAndIncrement("hello" + (count++)) + .get(); + return "incremented"; + } + + @GET + @Path("/get") + public String get() { + + return comparator.loadAndGet() + .visit(s->s,e->"Error loading " + e.getMessage()); + + } + + + @GET + @Path("/check") + public String check() { + return "" + !comparator.isOutOfDate() + .getOrElse(null); + + } +} diff --git a/micro-async-data-writer/src/test/java/app/writer/configured/com/oath/micro/server/ManifestComparatorRunnerTest.java b/micro-async-data-writer/src/test/java/app/writer/configured/com/oath/micro/server/ManifestComparatorRunnerTest.java new file mode 100644 index 000000000..dd8ba45b5 --- /dev/null +++ b/micro-async-data-writer/src/test/java/app/writer/configured/com/oath/micro/server/ManifestComparatorRunnerTest.java @@ -0,0 +1,62 @@ +package app.writer.configured.com.oath.micro.server; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import org.couchbase.mock.CouchbaseMock; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.testing.RestAgent; + +@Microserver(properties = { "couchbaseServers", "http://localhost:8091/pools", "couchbasePassword", "", + "couchbaseBucket", "beer-sample", "couchbase.manifest.comparison.key", "test-key" }) +public class ManifestComparatorRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + + @Before + public void startServer() { + try { + // couchbase already running? + rest.get("http://localhost:8091/pools"); + } catch (Exception e) { + // start mock couchbase + CouchbaseMock.main(new String[] { "-S" }); + } + server = new MicroserverApp( + () -> "simple-app"); + + server.start(); + + } + + @After + public void stopServer() { + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException { + rest.get("http://localhost:8080/simple-app/comparator/increment"); + + assertThat(rest.get("http://localhost:8080/simple-app/comparator/check"), equalTo("true")); + assertThat(rest.get("http://localhost:8080/simple-app/comparator/get"), equalTo("hello1")); + rest.get("http://localhost:8080/simple-app/comparator/increment"); + assertThat(rest.get("http://localhost:8080/simple-app/comparator/get"), equalTo("hello2")); + + rest.get("http://localhost:8080/simple-app/comparator2/increment"); + + assertThat(rest.get("http://localhost:8080/simple-app/comparator/check"), equalTo("false")); + assertThat(rest.get("http://localhost:8080/simple-app/comparator/get"), equalTo("hellob")); + + } + +} diff --git a/micro-async-data-writer/src/test/java/app/writer/configured/com/oath/micro/server/SecondComparatorResource.java b/micro-async-data-writer/src/test/java/app/writer/configured/com/oath/micro/server/SecondComparatorResource.java new file mode 100644 index 000000000..dcc9c9179 --- /dev/null +++ b/micro-async-data-writer/src/test/java/app/writer/configured/com/oath/micro/server/SecondComparatorResource.java @@ -0,0 +1,44 @@ +package app.writer.configured.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +import org.springframework.beans.factory.annotation.Autowired; + +import com.oath.micro.server.auto.discovery.Rest; +import com.oath.micro.server.manifest.ManifestComparator; + +@Path("/comparator2") +@Rest +public class SecondComparatorResource { + + private final ManifestComparator comparator; + + @Autowired + public SecondComparatorResource(ManifestComparator comparator) { + this.comparator = comparator.withKey("test-key"); + } + + @GET + @Path("/increment") + public String bucket() { + comparator.saveAndIncrement("hellob"); + return "increment"; + } + + @GET + @Path("/get") + public String get() { + comparator.load(); + return comparator.getData() + .toString(); + + } + + @GET + @Path("/check") + public String check() { + return "" + !comparator.isOutOfDate(); + + } +} \ No newline at end of file diff --git a/micro-async-data-writer/src/test/java/com/aol/micro/server/testing/RestAgent.java b/micro-async-data-writer/src/test/java/com/aol/micro/server/testing/RestAgent.java deleted file mode 100644 index ce204f810..000000000 --- a/micro-async-data-writer/src/test/java/com/aol/micro/server/testing/RestAgent.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.aol.micro.server.testing; - -import java.util.List; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.Invocation.Builder; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; - -import com.aol.micro.server.rest.jackson.JacksonUtil; - -public class RestAgent { - - - public String getJson(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.get(String.class); - - } - - public String get(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.TEXT_PLAIN); - - return request.get(String.class); - - } - - public T post(String url, Object payload,Class type) { - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); - } - - -} diff --git a/micro-async-data-writer/src/test/java/com/aol/micro/server/async/data/writer/AsyncDataWriterTest.java b/micro-async-data-writer/src/test/java/com/oath/micro/server/async/data/writer/AsyncDataWriterTest.java similarity index 93% rename from micro-async-data-writer/src/test/java/com/aol/micro/server/async/data/writer/AsyncDataWriterTest.java rename to micro-async-data-writer/src/test/java/com/oath/micro/server/async/data/writer/AsyncDataWriterTest.java index 798e646dd..9ff09968b 100644 --- a/micro-async-data-writer/src/test/java/com/aol/micro/server/async/data/writer/AsyncDataWriterTest.java +++ b/micro-async-data-writer/src/test/java/com/oath/micro/server/async/data/writer/AsyncDataWriterTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.async.data.writer; +package com.oath.micro.server.async.data.writer; import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertThat; @@ -8,13 +8,12 @@ import java.util.concurrent.atomic.AtomicInteger; import cyclops.async.Future; -import cyclops.control.Option; import cyclops.control.Try; import org.junit.Before; import org.junit.Test; -import com.aol.micro.server.events.SystemData; +import com.oath.micro.server.events.SystemData; import com.google.common.eventbus.EventBus; import com.google.common.eventbus.Subscribe; diff --git a/micro-async-data-writer/src/test/java/com/aol/micro/server/async/data/writer/DummyDataWriter.java b/micro-async-data-writer/src/test/java/com/oath/micro/server/async/data/writer/DummyDataWriter.java similarity index 92% rename from micro-async-data-writer/src/test/java/com/aol/micro/server/async/data/writer/DummyDataWriter.java rename to micro-async-data-writer/src/test/java/com/oath/micro/server/async/data/writer/DummyDataWriter.java index afe60852f..5b5d3a87d 100644 --- a/micro-async-data-writer/src/test/java/com/aol/micro/server/async/data/writer/DummyDataWriter.java +++ b/micro-async-data-writer/src/test/java/com/oath/micro/server/async/data/writer/DummyDataWriter.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.async.data.writer; +package com.oath.micro.server.async.data.writer; diff --git a/micro-async-data-writer/src/test/java/com/aol/micro/server/async/data/writer/DummyManifestComparator.java b/micro-async-data-writer/src/test/java/com/oath/micro/server/async/data/writer/DummyManifestComparator.java similarity index 93% rename from micro-async-data-writer/src/test/java/com/aol/micro/server/async/data/writer/DummyManifestComparator.java rename to micro-async-data-writer/src/test/java/com/oath/micro/server/async/data/writer/DummyManifestComparator.java index 0db45c334..8c06e168f 100644 --- a/micro-async-data-writer/src/test/java/com/aol/micro/server/async/data/writer/DummyManifestComparator.java +++ b/micro-async-data-writer/src/test/java/com/oath/micro/server/async/data/writer/DummyManifestComparator.java @@ -1,8 +1,8 @@ -package com.aol.micro.server.async.data.writer; +package com.oath.micro.server.async.data.writer; import java.util.concurrent.atomic.AtomicInteger; -import com.aol.micro.server.manifest.ManifestComparator; +import com.oath.micro.server.manifest.ManifestComparator; import lombok.Getter; import lombok.Setter; diff --git a/micro-async-data-writer/src/test/java/com/aol/micro/server/async/data/writer/MultiDataWriterTest.java b/micro-async-data-writer/src/test/java/com/oath/micro/server/async/data/writer/MultiDataWriterTest.java similarity index 98% rename from micro-async-data-writer/src/test/java/com/aol/micro/server/async/data/writer/MultiDataWriterTest.java rename to micro-async-data-writer/src/test/java/com/oath/micro/server/async/data/writer/MultiDataWriterTest.java index b3effb130..17708b814 100644 --- a/micro-async-data-writer/src/test/java/com/aol/micro/server/async/data/writer/MultiDataWriterTest.java +++ b/micro-async-data-writer/src/test/java/com/oath/micro/server/async/data/writer/MultiDataWriterTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.async.data.writer; +package com.oath.micro.server.async.data.writer; import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertThat; diff --git a/micro-async-data-writer/src/test/java/com/oath/micro/server/testing/RestAgent.java b/micro-async-data-writer/src/test/java/com/oath/micro/server/testing/RestAgent.java new file mode 100644 index 000000000..b2b86303e --- /dev/null +++ b/micro-async-data-writer/src/test/java/com/oath/micro/server/testing/RestAgent.java @@ -0,0 +1,53 @@ +package com.oath.micro.server.testing; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.Invocation.Builder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; + +import com.oath.micro.server.rest.jackson.JacksonUtil; + +public class RestAgent { + + + public String getJson(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.get(String.class); + + } + + public String get(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.TEXT_PLAIN); + + return request.get(String.class); + + } + + public T post(String url, Object payload,Class type) { + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); + } + + +} diff --git a/micro-boot/src/main/java/com/aol/micro/server/spring/boot/BootPlugin.java b/micro-boot/src/main/java/com/aol/micro/server/spring/boot/BootPlugin.java deleted file mode 100644 index fc2ab302b..000000000 --- a/micro-boot/src/main/java/com/aol/micro/server/spring/boot/BootPlugin.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.aol.micro.server.spring.boot; - -import com.aol.micro.server.Plugin; -import com.aol.micro.server.spring.SpringBuilder; - -/** - * - * @author johnmcclean - * - */ -public class BootPlugin implements Plugin{ - - - /** - * @return Engine for building Spring Context - */ - public SpringBuilder springBuilder(){ - return new BootApplicationConfigurator(); - } - - -} diff --git a/micro-boot/src/main/java/com/aol/micro/server/spring/boot/JerseySpringBootFrontEndApplication.java b/micro-boot/src/main/java/com/aol/micro/server/spring/boot/JerseySpringBootFrontEndApplication.java deleted file mode 100644 index 06f750e98..000000000 --- a/micro-boot/src/main/java/com/aol/micro/server/spring/boot/JerseySpringBootFrontEndApplication.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.aol.micro.server.spring.boot; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.Properties; - -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.context.embedded.EmbeddedServletContainer; -import org.springframework.boot.context.embedded.EmbeddedServletContainerException; -import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; -import org.springframework.boot.context.web.SpringBootServletInitializer; -import org.springframework.context.ApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.PropertySource; - -import com.aol.micro.server.module.Environment; -import com.aol.micro.server.servers.AccessLogLocationBean; -import com.aol.micro.server.spring.properties.PropertyFileConfig; - - -@Configuration -@PropertySource("classpath:spring-boot-microserver.properties") -public class JerseySpringBootFrontEndApplication extends SpringBootServletInitializer { - - List classes; - - public JerseySpringBootFrontEndApplication(){ - classes = new ArrayList<>(); - } - - public JerseySpringBootFrontEndApplication(List classes2) { - classes = new ArrayList<>(); - classes.addAll(classes2); - classes.add(JerseySpringBootFrontEndApplication.class); - classes.add(PropertyFileConfig.class); - classes.add(Environment.class); - classes.add(AccessLogLocationBean.class); - } - - - @Override - protected SpringApplicationBuilder configure( - SpringApplicationBuilder application) { - - return application.sources(classes.toArray(new Class[0])); - } - - public SpringApplicationBuilder config(SpringApplicationBuilder builder) { - return configure(builder); - - } - - @Bean - public AccessLogLocationBean createAccessLogLocationBean( - ApplicationContext rootContext) { - Properties props = (Properties) rootContext.getBean("propertyFactory"); - String location = Optional.ofNullable( - (String) props.get("access.log.output")).orElse("./logs/"); - return new AccessLogLocationBean(location); - } - - - - - - - -} diff --git a/micro-boot/src/main/java/com/aol/micro/server/boot/config/Microboot.java b/micro-boot/src/main/java/com/oath/micro/server/boot/config/Microboot.java similarity index 92% rename from micro-boot/src/main/java/com/aol/micro/server/boot/config/Microboot.java rename to micro-boot/src/main/java/com/oath/micro/server/boot/config/Microboot.java index 4957fe1d5..c4bb6265c 100644 --- a/micro-boot/src/main/java/com/aol/micro/server/boot/config/Microboot.java +++ b/micro-boot/src/main/java/com/oath/micro/server/boot/config/Microboot.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.boot.config; +package com.oath.micro.server.boot.config; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/micro-boot/src/main/java/com/aol/micro/server/spring/boot/BootApplicationConfigurator.java b/micro-boot/src/main/java/com/oath/micro/server/spring/boot/BootApplicationConfigurator.java similarity index 85% rename from micro-boot/src/main/java/com/aol/micro/server/spring/boot/BootApplicationConfigurator.java rename to micro-boot/src/main/java/com/oath/micro/server/spring/boot/BootApplicationConfigurator.java index 24beb3017..036051df4 100644 --- a/micro-boot/src/main/java/com/aol/micro/server/spring/boot/BootApplicationConfigurator.java +++ b/micro-boot/src/main/java/com/oath/micro/server/spring/boot/BootApplicationConfigurator.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.spring.boot; +package com.oath.micro.server.spring.boot; import java.util.ArrayList; @@ -10,8 +10,8 @@ import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.context.ConfigurableApplicationContext; -import com.aol.micro.server.config.Config; -import com.aol.micro.server.spring.SpringBuilder; +import com.oath.micro.server.config.Config; +import com.oath.micro.server.spring.SpringBuilder; public class BootApplicationConfigurator implements SpringBuilder { private final Logger logger = LoggerFactory.getLogger(this.getClass()); diff --git a/micro-boot/src/main/java/com/oath/micro/server/spring/boot/BootPlugin.java b/micro-boot/src/main/java/com/oath/micro/server/spring/boot/BootPlugin.java new file mode 100644 index 000000000..8f0ffdb72 --- /dev/null +++ b/micro-boot/src/main/java/com/oath/micro/server/spring/boot/BootPlugin.java @@ -0,0 +1,22 @@ +package com.oath.micro.server.spring.boot; + +import com.oath.micro.server.Plugin; +import com.oath.micro.server.spring.SpringBuilder; + +/** + * + * @author johnmcclean + * + */ +public class BootPlugin implements Plugin{ + + + /** + * @return Engine for building Spring Context + */ + public SpringBuilder springBuilder(){ + return new BootApplicationConfigurator(); + } + + +} diff --git a/micro-boot/src/main/java/com/aol/micro/server/spring/boot/JerseyApplication.java b/micro-boot/src/main/java/com/oath/micro/server/spring/boot/JerseyApplication.java similarity index 91% rename from micro-boot/src/main/java/com/aol/micro/server/spring/boot/JerseyApplication.java rename to micro-boot/src/main/java/com/oath/micro/server/spring/boot/JerseyApplication.java index f0048927c..c9084a81c 100644 --- a/micro-boot/src/main/java/com/aol/micro/server/spring/boot/JerseyApplication.java +++ b/micro-boot/src/main/java/com/oath/micro/server/spring/boot/JerseyApplication.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.spring.boot; +package com.oath.micro.server.spring.boot; import java.util.ArrayList; import java.util.List; @@ -15,9 +15,9 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; -import com.aol.micro.server.module.Environment; -import com.aol.micro.server.servers.AccessLogLocationBean; -import com.aol.micro.server.spring.properties.PropertyFileConfig; +import com.oath.micro.server.module.Environment; +import com.oath.micro.server.servers.AccessLogLocationBean; +import com.oath.micro.server.spring.properties.PropertyFileConfig; @Configuration diff --git a/micro-boot/src/main/java/com/oath/micro/server/spring/boot/JerseySpringBootFrontEndApplication.java b/micro-boot/src/main/java/com/oath/micro/server/spring/boot/JerseySpringBootFrontEndApplication.java new file mode 100644 index 000000000..606b8f16d --- /dev/null +++ b/micro-boot/src/main/java/com/oath/micro/server/spring/boot/JerseySpringBootFrontEndApplication.java @@ -0,0 +1,67 @@ +package com.oath.micro.server.spring.boot; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.Properties; + +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.context.web.SpringBootServletInitializer; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; + +import com.oath.micro.server.module.Environment; +import com.oath.micro.server.servers.AccessLogLocationBean; +import com.oath.micro.server.spring.properties.PropertyFileConfig; + + +@Configuration +@PropertySource("classpath:spring-boot-microserver.properties") +public class JerseySpringBootFrontEndApplication extends SpringBootServletInitializer { + + List classes; + + public JerseySpringBootFrontEndApplication(){ + classes = new ArrayList<>(); + } + + public JerseySpringBootFrontEndApplication(List classes2) { + classes = new ArrayList<>(); + classes.addAll(classes2); + classes.add(JerseySpringBootFrontEndApplication.class); + classes.add(PropertyFileConfig.class); + classes.add(Environment.class); + classes.add(AccessLogLocationBean.class); + } + + + @Override + protected SpringApplicationBuilder configure( + SpringApplicationBuilder application) { + + return application.sources(classes.toArray(new Class[0])); + } + + public SpringApplicationBuilder config(SpringApplicationBuilder builder) { + return configure(builder); + + } + + @Bean + public AccessLogLocationBean createAccessLogLocationBean( + ApplicationContext rootContext) { + Properties props = (Properties) rootContext.getBean("propertyFactory"); + String location = Optional.ofNullable( + (String) props.get("access.log.output")).orElse("./logs/"); + return new AccessLogLocationBean(location); + } + + + + + + + +} diff --git a/micro-boot/src/main/resources/META-INF/services/com.aol.micro.server.Plugin b/micro-boot/src/main/resources/META-INF/services/com.aol.micro.server.Plugin deleted file mode 100644 index 3e9503978..000000000 --- a/micro-boot/src/main/resources/META-INF/services/com.aol.micro.server.Plugin +++ /dev/null @@ -1 +0,0 @@ -com.aol.micro.server.spring.boot.BootPlugin \ No newline at end of file diff --git a/micro-boot/src/main/resources/META-INF/services/com.oath.micro.server.Plugin b/micro-boot/src/main/resources/META-INF/services/com.oath.micro.server.Plugin new file mode 100644 index 000000000..e726bf190 --- /dev/null +++ b/micro-boot/src/main/resources/META-INF/services/com.oath.micro.server.Plugin @@ -0,0 +1 @@ +com.oath.micro.server.spring.boot.BootPlugin \ No newline at end of file diff --git a/micro-boot/src/test/java/app/boot/com/aol/micro/server/AsyncAppRunner.java b/micro-boot/src/test/java/app/boot/com/aol/micro/server/AsyncAppRunner.java deleted file mode 100644 index 447bcece4..000000000 --- a/micro-boot/src/test/java/app/boot/com/aol/micro/server/AsyncAppRunner.java +++ /dev/null @@ -1,49 +0,0 @@ -package app.boot.com.aol.micro.server; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.boot.config.Microboot; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.rest.client.nio.AsyncRestClient; - -@Microserver @Microboot -public class AsyncAppRunner { - - - AsyncRestClient rest = new AsyncRestClient(1000,1000).withAccept("text/plain"); - - MicroserverApp server; - @Before - public void startServer(){ - - server = new MicroserverApp( ()-> "async-app"); - server.start(); - - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - Thread.sleep(2000); - - assertThat(rest.get("http://localhost:8080/async-app/async/expensive").get(),is(";test!;test!;test!")); - - } - - - -} \ No newline at end of file diff --git a/micro-boot/src/test/java/app/boot/com/aol/micro/server/AsyncResource.java b/micro-boot/src/test/java/app/boot/com/aol/micro/server/AsyncResource.java deleted file mode 100644 index 9c7f53617..000000000 --- a/micro-boot/src/test/java/app/boot/com/aol/micro/server/AsyncResource.java +++ /dev/null @@ -1,56 +0,0 @@ -package app.boot.com.aol.micro.server; - -import java.util.List; -import java.util.concurrent.CompletableFuture; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.container.AsyncResponse; -import javax.ws.rs.container.Suspended; - -import cyclops.async.SimpleReact; -import org.springframework.stereotype.Component; - - -import com.aol.micro.server.auto.discovery.RestResource; -import com.aol.micro.server.rest.client.nio.AsyncRestClient; -import com.google.common.collect.ImmutableList; - -@Path("/async") -@Component -public class AsyncResource implements RestResource{ - - private final SimpleReact simpleReact =new SimpleReact(); - private final ImmutableList urls = ImmutableList.of("http://localhost:8080/async-app/async/ping2", - "http://localhost:8080/async-app/async/ping", - "http://localhost:8080/async-app/async/ping", - "http://localhost:8080/async-app/async/ping"); - - private final AsyncRestClient client = new AsyncRestClient(1000,1000).withAccept("text/plain"); - - @GET - @Path("/expensive") - @Produces("text/plain") - public void expensive(@Suspended AsyncResponse asyncResponse){ - - simpleReact.fromStream(urls.stream() - .>map(it -> client.get(it))) - .onFail(it -> "") - .peek(it -> - System.out.println(it)) - .allOf(data -> { - System.out.println(data); - return asyncResponse.resume(String.join(";", (List)data)); }); - - } - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "test!"; - } - - -} diff --git a/micro-boot/src/test/java/app/boot/com/aol/micro/server/SimpleApp.java b/micro-boot/src/test/java/app/boot/com/aol/micro/server/SimpleApp.java deleted file mode 100644 index 41cdbc63e..000000000 --- a/micro-boot/src/test/java/app/boot/com/aol/micro/server/SimpleApp.java +++ /dev/null @@ -1,12 +0,0 @@ -package app.boot.com.aol.micro.server; - -import com.aol.micro.server.MicroserverApp; - - -public class SimpleApp { - - public static void main(String[] args){ - new MicroserverApp(()->"test-app").run(); - } - -} diff --git a/micro-boot/src/test/java/app/boot/com/oath/micro/server/AsyncAppRunner.java b/micro-boot/src/test/java/app/boot/com/oath/micro/server/AsyncAppRunner.java new file mode 100644 index 000000000..7737faf12 --- /dev/null +++ b/micro-boot/src/test/java/app/boot/com/oath/micro/server/AsyncAppRunner.java @@ -0,0 +1,49 @@ +package app.boot.com.oath.micro.server; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.boot.config.Microboot; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.rest.client.nio.AsyncRestClient; + +@Microserver @Microboot +public class AsyncAppRunner { + + + AsyncRestClient rest = new AsyncRestClient(1000,1000).withAccept("text/plain"); + + MicroserverApp server; + @Before + public void startServer(){ + + server = new MicroserverApp( ()-> "async-app"); + server.start(); + + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + Thread.sleep(2000); + + assertThat(rest.get("http://localhost:8080/async-app/async/expensive").get(),is(";test!;test!;test!")); + + } + + + +} \ No newline at end of file diff --git a/micro-boot/src/test/java/app/boot/com/oath/micro/server/AsyncResource.java b/micro-boot/src/test/java/app/boot/com/oath/micro/server/AsyncResource.java new file mode 100644 index 000000000..9acd42c8c --- /dev/null +++ b/micro-boot/src/test/java/app/boot/com/oath/micro/server/AsyncResource.java @@ -0,0 +1,56 @@ +package app.boot.com.oath.micro.server; + +import java.util.List; +import java.util.concurrent.CompletableFuture; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.container.AsyncResponse; +import javax.ws.rs.container.Suspended; + +import cyclops.async.SimpleReact; +import org.springframework.stereotype.Component; + + +import com.oath.micro.server.auto.discovery.RestResource; +import com.oath.micro.server.rest.client.nio.AsyncRestClient; +import com.google.common.collect.ImmutableList; + +@Path("/async") +@Component +public class AsyncResource implements RestResource{ + + private final SimpleReact simpleReact =new SimpleReact(); + private final ImmutableList urls = ImmutableList.of("http://localhost:8080/async-app/async/ping2", + "http://localhost:8080/async-app/async/ping", + "http://localhost:8080/async-app/async/ping", + "http://localhost:8080/async-app/async/ping"); + + private final AsyncRestClient client = new AsyncRestClient(1000,1000).withAccept("text/plain"); + + @GET + @Path("/expensive") + @Produces("text/plain") + public void expensive(@Suspended AsyncResponse asyncResponse){ + + simpleReact.fromStream(urls.stream() + .>map(it -> client.get(it))) + .onFail(it -> "") + .peek(it -> + System.out.println(it)) + .allOf(data -> { + System.out.println(data); + return asyncResponse.resume(String.join(";", (List)data)); }); + + } + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "test!"; + } + + +} diff --git a/micro-boot/src/test/java/app/boot/com/oath/micro/server/SimpleApp.java b/micro-boot/src/test/java/app/boot/com/oath/micro/server/SimpleApp.java new file mode 100644 index 000000000..29820978c --- /dev/null +++ b/micro-boot/src/test/java/app/boot/com/oath/micro/server/SimpleApp.java @@ -0,0 +1,12 @@ +package app.boot.com.oath.micro.server; + +import com.oath.micro.server.MicroserverApp; + + +public class SimpleApp { + + public static void main(String[] args){ + new MicroserverApp(()->"test-app").run(); + } + +} diff --git a/micro-boot/src/test/java/app/boot/embedded/com/aol/micro/server/AltAppResource.java b/micro-boot/src/test/java/app/boot/embedded/com/aol/micro/server/AltAppResource.java deleted file mode 100644 index facee2f8a..000000000 --- a/micro-boot/src/test/java/app/boot/embedded/com/aol/micro/server/AltAppResource.java +++ /dev/null @@ -1,21 +0,0 @@ -package app.boot.embedded.com.aol.micro.server; - -import java.util.List; - -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - - -@AltAppRestResource -@Path("/alt-status") -public class AltAppResource { - - @POST - @Produces("application/json") - @Path("/ping") - public List ping(ImmutableEntity entity) { - return entity.getList(); - } - -} diff --git a/micro-boot/src/test/java/app/boot/embedded/com/aol/micro/server/AltAppRestResource.java b/micro-boot/src/test/java/app/boot/embedded/com/aol/micro/server/AltAppRestResource.java deleted file mode 100644 index fc7803727..000000000 --- a/micro-boot/src/test/java/app/boot/embedded/com/aol/micro/server/AltAppRestResource.java +++ /dev/null @@ -1,15 +0,0 @@ -package app.boot.embedded.com.aol.micro.server; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import com.aol.micro.server.auto.discovery.Rest; - -@Rest -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -public @interface AltAppRestResource { - -} diff --git a/micro-boot/src/test/java/app/boot/embedded/com/aol/micro/server/EmbeddedAppLocalMain.java b/micro-boot/src/test/java/app/boot/embedded/com/aol/micro/server/EmbeddedAppLocalMain.java deleted file mode 100644 index adfe9570d..000000000 --- a/micro-boot/src/test/java/app/boot/embedded/com/aol/micro/server/EmbeddedAppLocalMain.java +++ /dev/null @@ -1,25 +0,0 @@ -package app.boot.embedded.com.aol.micro.server; - -import java.util.Arrays; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.boot.config.Microboot; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.module.EmbeddedModule; - -@Microserver @Microboot//(basePackages = { "app.boot.embedded.com.aol.micro.server" }) -public class EmbeddedAppLocalMain { - - - public static void main(String[] args) throws InterruptedException { - - new MicroserverApp( - EmbeddedModule.tagInterfaceModule(Arrays.asList(TestAppRestResource.class),"test-app"), - EmbeddedModule.tagInterfaceModule(Arrays.asList(AltAppRestResource.class),"alternative-app")).start(); - - - - } - - -} diff --git a/micro-boot/src/test/java/app/boot/embedded/com/aol/micro/server/EmbeddedAppTest.java b/micro-boot/src/test/java/app/boot/embedded/com/aol/micro/server/EmbeddedAppTest.java deleted file mode 100644 index 3a878873c..000000000 --- a/micro-boot/src/test/java/app/boot/embedded/com/aol/micro/server/EmbeddedAppTest.java +++ /dev/null @@ -1,103 +0,0 @@ -package app.boot.embedded.com.aol.micro.server; - -import static org.hamcrest.Matchers.hasItem; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; - -import javax.ws.rs.NotFoundException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.springframework.util.concurrent.ListenableFuture; -import org.springframework.util.concurrent.ListenableFutureCallback; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.module.EmbeddedModule; -import com.aol.micro.server.testing.RestAgent; -import com.google.common.collect.ImmutableList; - -public class EmbeddedAppTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - - @Before - public void startServer(){ - server = new MicroserverApp(EmbeddedAppLocalMain.class, - EmbeddedModule.annotationModule(Arrays.asList(TestAppRestResource.class),"test-app"), - EmbeddedModule.annotationModule(Arrays.asList(AltAppRestResource.class),"alternative-app")); - server.start(); - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void confirmExpectedUrlsPresentTest() throws InterruptedException, ExecutionException{ - - assertThat(rest.get("http://localhost:8080/test-app/test-status/ping"),is("test!")); - - - assertThat((List)rest.post("http://localhost:8081/alternative-app/alt-status/ping",new ImmutableEntity("value",ImmutableList.of("hello","world")),List.class), - hasItem("hello")); - - } - - - @Test - public void nonBlockingRestClientTest(){ - assertThat(rest.get("http://localhost:8080/test-app/test-status/rest-calls"),is("-*test!-*test!")); - } - - CompletableFuture toCompletableFuture( - final ListenableFuture listenableFuture - ) { - //create an instance of CompletableFuture - CompletableFuture completable = new CompletableFuture() { - @Override - public boolean cancel(boolean mayInterruptIfRunning) { - // propagate cancel to the listenable future - boolean result = listenableFuture.cancel(mayInterruptIfRunning); - super.cancel(mayInterruptIfRunning); - return result; - } - }; - - // add callback - listenableFuture.addCallback(new ListenableFutureCallback() { - @Override - public void onSuccess(T result) { - completable.complete(result); - } - - @Override - public void onFailure(Throwable t) { - completable.completeExceptionally(t); - } - }); - return completable; - } - - @Test(expected=NotFoundException.class) - public void confirmAltAppCantUseTestAppResources(){ - - assertThat(rest.get("http://localhost:8080/alternative-app/test-status/ping"),is("test!")); - - } - @Test(expected=NotFoundException.class) - public void confirmTestAppCantUseAltAppResources(){ - - assertThat((List)rest.post("http://localhost:8081/test-app/alt-status/ping",new ImmutableEntity("value",ImmutableList.of("hello","world")),List.class), - hasItem("hello")); - - } -} diff --git a/micro-boot/src/test/java/app/boot/embedded/com/aol/micro/server/ImmutableEntity.java b/micro-boot/src/test/java/app/boot/embedded/com/aol/micro/server/ImmutableEntity.java deleted file mode 100644 index 0e98dc35b..000000000 --- a/micro-boot/src/test/java/app/boot/embedded/com/aol/micro/server/ImmutableEntity.java +++ /dev/null @@ -1,29 +0,0 @@ -package app.boot.embedded.com.aol.micro.server; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Builder; - -import com.google.common.collect.ImmutableList; - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "") -@XmlRootElement(name = "immutable") -@Getter -@AllArgsConstructor -@Builder -public class ImmutableEntity { - - private final String value; - private final ImmutableList list; - - public ImmutableEntity() { - this(null,null); - } - -} diff --git a/micro-boot/src/test/java/app/boot/embedded/com/aol/micro/server/TestAppResource.java b/micro-boot/src/test/java/app/boot/embedded/com/aol/micro/server/TestAppResource.java deleted file mode 100644 index 9a4a10121..000000000 --- a/micro-boot/src/test/java/app/boot/embedded/com/aol/micro/server/TestAppResource.java +++ /dev/null @@ -1,53 +0,0 @@ -package app.boot.embedded.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import cyclops.async.SimpleReact; -import org.springframework.beans.factory.annotation.Autowired; - - -import com.aol.micro.server.rest.client.nio.NIORestClient; -import com.google.common.collect.ImmutableList; -//@Component -@TestAppRestResource -@Path("/test-status") -public class TestAppResource { - - private final SimpleReact simpleReact = new SimpleReact(); - private final NIORestClient template; - private final ImmutableList urls = ImmutableList.of("http://localhost:8081/alternative-app/alt-status/ping", - "http://localhost:8080/test-app/test-status/ping", - "http://localhost:8082/simple-app/status/ping", - "http://localhost:8080/test-app/test-status/ping"); - - @Autowired - public TestAppResource(NIORestClient template) { - - this.template = template; - } - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "test!"; - } - - @GET - @Produces("text/plain") - @Path("/rest-calls") - public String restCallResult(){ - - return simpleReact - .fromStream(urls.stream() - .map(it -> template.getForEntity(it,String.class))) - .then(it -> it.getBody()) - .then(it -> "*"+it) - .peek(loadedAndModified -> System.out.println(loadedAndModified)) - .block().stream().reduce("", (acc,next) -> acc+"-"+next); - - } - -} diff --git a/micro-boot/src/test/java/app/boot/embedded/com/aol/micro/server/TestAppRestResource.java b/micro-boot/src/test/java/app/boot/embedded/com/aol/micro/server/TestAppRestResource.java deleted file mode 100644 index 3c0e7861b..000000000 --- a/micro-boot/src/test/java/app/boot/embedded/com/aol/micro/server/TestAppRestResource.java +++ /dev/null @@ -1,15 +0,0 @@ -package app.boot.embedded.com.aol.micro.server; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import com.aol.micro.server.auto.discovery.Rest; - -@Rest -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -public @interface TestAppRestResource{ - -} diff --git a/micro-boot/src/test/java/app/boot/embedded/com/oath/micro/server/AltAppResource.java b/micro-boot/src/test/java/app/boot/embedded/com/oath/micro/server/AltAppResource.java new file mode 100644 index 000000000..a5e3944a1 --- /dev/null +++ b/micro-boot/src/test/java/app/boot/embedded/com/oath/micro/server/AltAppResource.java @@ -0,0 +1,21 @@ +package app.boot.embedded.com.oath.micro.server; + +import java.util.List; + +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + + +@AltAppRestResource +@Path("/alt-status") +public class AltAppResource { + + @POST + @Produces("application/json") + @Path("/ping") + public List ping(ImmutableEntity entity) { + return entity.getList(); + } + +} diff --git a/micro-boot/src/test/java/app/boot/embedded/com/oath/micro/server/AltAppRestResource.java b/micro-boot/src/test/java/app/boot/embedded/com/oath/micro/server/AltAppRestResource.java new file mode 100644 index 000000000..617581f1b --- /dev/null +++ b/micro-boot/src/test/java/app/boot/embedded/com/oath/micro/server/AltAppRestResource.java @@ -0,0 +1,15 @@ +package app.boot.embedded.com.oath.micro.server; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import com.oath.micro.server.auto.discovery.Rest; + +@Rest +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface AltAppRestResource { + +} diff --git a/micro-boot/src/test/java/app/boot/embedded/com/oath/micro/server/EmbeddedAppLocalMain.java b/micro-boot/src/test/java/app/boot/embedded/com/oath/micro/server/EmbeddedAppLocalMain.java new file mode 100644 index 000000000..d2690d56d --- /dev/null +++ b/micro-boot/src/test/java/app/boot/embedded/com/oath/micro/server/EmbeddedAppLocalMain.java @@ -0,0 +1,25 @@ +package app.boot.embedded.com.oath.micro.server; + +import java.util.Arrays; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.boot.config.Microboot; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.module.EmbeddedModule; + +@Microserver @Microboot//(basePackages = { "app.boot.embedded.com.oath.micro.server" }) +public class EmbeddedAppLocalMain { + + + public static void main(String[] args) throws InterruptedException { + + new MicroserverApp( + EmbeddedModule.tagInterfaceModule(Arrays.asList(TestAppRestResource.class),"test-app"), + EmbeddedModule.tagInterfaceModule(Arrays.asList(AltAppRestResource.class),"alternative-app")).start(); + + + + } + + +} diff --git a/micro-boot/src/test/java/app/boot/embedded/com/oath/micro/server/EmbeddedAppTest.java b/micro-boot/src/test/java/app/boot/embedded/com/oath/micro/server/EmbeddedAppTest.java new file mode 100644 index 000000000..a94e9109e --- /dev/null +++ b/micro-boot/src/test/java/app/boot/embedded/com/oath/micro/server/EmbeddedAppTest.java @@ -0,0 +1,103 @@ +package app.boot.embedded.com.oath.micro.server; + +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; + +import javax.ws.rs.NotFoundException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.springframework.util.concurrent.ListenableFuture; +import org.springframework.util.concurrent.ListenableFutureCallback; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.module.EmbeddedModule; +import com.oath.micro.server.testing.RestAgent; +import com.google.common.collect.ImmutableList; + +public class EmbeddedAppTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + + @Before + public void startServer(){ + server = new MicroserverApp(EmbeddedAppLocalMain.class, + EmbeddedModule.annotationModule(Arrays.asList(TestAppRestResource.class),"test-app"), + EmbeddedModule.annotationModule(Arrays.asList(AltAppRestResource.class),"alternative-app")); + server.start(); + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void confirmExpectedUrlsPresentTest() throws InterruptedException, ExecutionException{ + + assertThat(rest.get("http://localhost:8080/test-app/test-status/ping"),is("test!")); + + + assertThat((List)rest.post("http://localhost:8081/alternative-app/alt-status/ping",new ImmutableEntity("value",ImmutableList.of("hello","world")),List.class), + hasItem("hello")); + + } + + + @Test + public void nonBlockingRestClientTest(){ + assertThat(rest.get("http://localhost:8080/test-app/test-status/rest-calls"),is("-*test!-*test!")); + } + + CompletableFuture toCompletableFuture( + final ListenableFuture listenableFuture + ) { + //create an instance of CompletableFuture + CompletableFuture completable = new CompletableFuture() { + @Override + public boolean cancel(boolean mayInterruptIfRunning) { + // propagate cancel to the listenable future + boolean result = listenableFuture.cancel(mayInterruptIfRunning); + super.cancel(mayInterruptIfRunning); + return result; + } + }; + + // add callback + listenableFuture.addCallback(new ListenableFutureCallback() { + @Override + public void onSuccess(T result) { + completable.complete(result); + } + + @Override + public void onFailure(Throwable t) { + completable.completeExceptionally(t); + } + }); + return completable; + } + + @Test(expected=NotFoundException.class) + public void confirmAltAppCantUseTestAppResources(){ + + assertThat(rest.get("http://localhost:8080/alternative-app/test-status/ping"),is("test!")); + + } + @Test(expected=NotFoundException.class) + public void confirmTestAppCantUseAltAppResources(){ + + assertThat((List)rest.post("http://localhost:8081/test-app/alt-status/ping",new ImmutableEntity("value",ImmutableList.of("hello","world")),List.class), + hasItem("hello")); + + } +} diff --git a/micro-boot/src/test/java/app/boot/embedded/com/oath/micro/server/ImmutableEntity.java b/micro-boot/src/test/java/app/boot/embedded/com/oath/micro/server/ImmutableEntity.java new file mode 100644 index 000000000..1e291b624 --- /dev/null +++ b/micro-boot/src/test/java/app/boot/embedded/com/oath/micro/server/ImmutableEntity.java @@ -0,0 +1,29 @@ +package app.boot.embedded.com.oath.micro.server; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Builder; + +import com.google.common.collect.ImmutableList; + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "") +@XmlRootElement(name = "immutable") +@Getter +@AllArgsConstructor +@Builder +public class ImmutableEntity { + + private final String value; + private final ImmutableList list; + + public ImmutableEntity() { + this(null,null); + } + +} diff --git a/micro-boot/src/test/java/app/boot/embedded/com/oath/micro/server/TestAppResource.java b/micro-boot/src/test/java/app/boot/embedded/com/oath/micro/server/TestAppResource.java new file mode 100644 index 000000000..e019b0e8d --- /dev/null +++ b/micro-boot/src/test/java/app/boot/embedded/com/oath/micro/server/TestAppResource.java @@ -0,0 +1,53 @@ +package app.boot.embedded.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import cyclops.async.SimpleReact; +import org.springframework.beans.factory.annotation.Autowired; + + +import com.oath.micro.server.rest.client.nio.NIORestClient; +import com.google.common.collect.ImmutableList; +//@Component +@TestAppRestResource +@Path("/test-status") +public class TestAppResource { + + private final SimpleReact simpleReact = new SimpleReact(); + private final NIORestClient template; + private final ImmutableList urls = ImmutableList.of("http://localhost:8081/alternative-app/alt-status/ping", + "http://localhost:8080/test-app/test-status/ping", + "http://localhost:8082/simple-app/status/ping", + "http://localhost:8080/test-app/test-status/ping"); + + @Autowired + public TestAppResource(NIORestClient template) { + + this.template = template; + } + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "test!"; + } + + @GET + @Produces("text/plain") + @Path("/rest-calls") + public String restCallResult(){ + + return simpleReact + .fromStream(urls.stream() + .map(it -> template.getForEntity(it,String.class))) + .then(it -> it.getBody()) + .then(it -> "*"+it) + .peek(loadedAndModified -> System.out.println(loadedAndModified)) + .block().stream().reduce("", (acc,next) -> acc+"-"+next); + + } + +} diff --git a/micro-boot/src/test/java/app/boot/embedded/com/oath/micro/server/TestAppRestResource.java b/micro-boot/src/test/java/app/boot/embedded/com/oath/micro/server/TestAppRestResource.java new file mode 100644 index 000000000..537c78247 --- /dev/null +++ b/micro-boot/src/test/java/app/boot/embedded/com/oath/micro/server/TestAppRestResource.java @@ -0,0 +1,15 @@ +package app.boot.embedded.com.oath.micro.server; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import com.oath.micro.server.auto.discovery.Rest; + +@Rest +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface TestAppRestResource{ + +} diff --git a/micro-boot/src/test/java/app/boot/events/com/aol/micro/server/EventRunnerTest.java b/micro-boot/src/test/java/app/boot/events/com/aol/micro/server/EventRunnerTest.java deleted file mode 100644 index cdeed1b3d..000000000 --- a/micro-boot/src/test/java/app/boot/events/com/aol/micro/server/EventRunnerTest.java +++ /dev/null @@ -1,59 +0,0 @@ -package app.boot.events.com.aol.micro.server; - - -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.boot.config.Microboot; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.rest.client.nio.AsyncRestClient; -import com.aol.micro.server.testing.RestAgent; - -@Microserver @Microboot -public class EventRunnerTest { - - RestAgent rest = new RestAgent(); - private final AsyncRestClient client = new AsyncRestClient(1000,1000).withAccept("application/json"); - MicroserverApp server; - - - @Before - public void startServer(){ - - server = new MicroserverApp(()-> "event-app"); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - - - assertThat(rest.get("http://localhost:8080/event-app/status/ping"),is("ok")); - - assertThat(client.get("http://localhost:8080/event-app/active/jobs").get(), - containsString("startedAt")); - assertThat(client.get("http://localhost:8080/event-app/active/requests").get(), - containsString("startedAt")); - assertThat(client.get("http://localhost:8080/event-app/manifest").get(), - containsString("Manifest")); - - } - - - -} diff --git a/micro-boot/src/test/java/app/boot/events/com/aol/micro/server/EventStatusResource.java b/micro-boot/src/test/java/app/boot/events/com/aol/micro/server/EventStatusResource.java deleted file mode 100644 index 4a17b5de9..000000000 --- a/micro-boot/src/test/java/app/boot/events/com/aol/micro/server/EventStatusResource.java +++ /dev/null @@ -1,40 +0,0 @@ -package app.boot.events.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.RestResource; -import com.aol.micro.server.events.RequestEvents; -import com.google.common.eventbus.EventBus; - -@Component -@Path("/status") -public class EventStatusResource implements RestResource { - - - - - private final EventBus bus; - - @Autowired - public EventStatusResource(EventBus bus ){ - this.bus = bus; - } - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - bus.post(RequestEvents.start("get", 1l)); - try{ - return "ok"; - }finally{ - bus.post(RequestEvents.finish("get",1l)); - } - } - -} \ No newline at end of file diff --git a/micro-boot/src/test/java/app/boot/events/com/aol/micro/server/Job.java b/micro-boot/src/test/java/app/boot/events/com/aol/micro/server/Job.java deleted file mode 100644 index 8978963fd..000000000 --- a/micro-boot/src/test/java/app/boot/events/com/aol/micro/server/Job.java +++ /dev/null @@ -1,16 +0,0 @@ -package app.boot.events.com.aol.micro.server; - -import org.springframework.stereotype.Component; - -import com.aol.micro.server.events.ScheduledJob; -import com.aol.micro.server.events.SystemData; - -@Component -public class Job implements ScheduledJob{ - - @Override - public SystemData scheduleAndLog() { - return SystemData.builder().errors(0).processed(2).build(); - } - -} diff --git a/micro-boot/src/test/java/app/boot/events/com/aol/micro/server/Schedular.java b/micro-boot/src/test/java/app/boot/events/com/aol/micro/server/Schedular.java deleted file mode 100644 index d68afd75c..000000000 --- a/micro-boot/src/test/java/app/boot/events/com/aol/micro/server/Schedular.java +++ /dev/null @@ -1,22 +0,0 @@ -package app.boot.events.com.aol.micro.server; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Component; - - -@Component -public class Schedular { - - private final Job job; - - @Autowired - public Schedular(final Job job){ - this.job=job; - } - - @Scheduled(fixedDelay=1) - public synchronized void scheduleTask(){ - job.scheduleAndLog(); - } -} diff --git a/micro-boot/src/test/java/app/boot/events/com/oath/micro/server/EventRunnerTest.java b/micro-boot/src/test/java/app/boot/events/com/oath/micro/server/EventRunnerTest.java new file mode 100644 index 000000000..29350f6bc --- /dev/null +++ b/micro-boot/src/test/java/app/boot/events/com/oath/micro/server/EventRunnerTest.java @@ -0,0 +1,59 @@ +package app.boot.events.com.oath.micro.server; + + +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.boot.config.Microboot; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.rest.client.nio.AsyncRestClient; +import com.oath.micro.server.testing.RestAgent; + +@Microserver @Microboot +public class EventRunnerTest { + + RestAgent rest = new RestAgent(); + private final AsyncRestClient client = new AsyncRestClient(1000,1000).withAccept("application/json"); + MicroserverApp server; + + + @Before + public void startServer(){ + + server = new MicroserverApp(()-> "event-app"); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + + + assertThat(rest.get("http://localhost:8080/event-app/status/ping"),is("ok")); + + assertThat(client.get("http://localhost:8080/event-app/active/jobs").get(), + containsString("startedAt")); + assertThat(client.get("http://localhost:8080/event-app/active/requests").get(), + containsString("startedAt")); + assertThat(client.get("http://localhost:8080/event-app/manifest").get(), + containsString("Manifest")); + + } + + + +} diff --git a/micro-boot/src/test/java/app/boot/events/com/oath/micro/server/EventStatusResource.java b/micro-boot/src/test/java/app/boot/events/com/oath/micro/server/EventStatusResource.java new file mode 100644 index 000000000..fadef80d6 --- /dev/null +++ b/micro-boot/src/test/java/app/boot/events/com/oath/micro/server/EventStatusResource.java @@ -0,0 +1,40 @@ +package app.boot.events.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.RestResource; +import com.oath.micro.server.events.RequestEvents; +import com.google.common.eventbus.EventBus; + +@Component +@Path("/status") +public class EventStatusResource implements RestResource { + + + + + private final EventBus bus; + + @Autowired + public EventStatusResource(EventBus bus ){ + this.bus = bus; + } + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + bus.post(RequestEvents.start("get", 1l)); + try{ + return "ok"; + }finally{ + bus.post(RequestEvents.finish("get",1l)); + } + } + +} \ No newline at end of file diff --git a/micro-boot/src/test/java/app/boot/events/com/oath/micro/server/Job.java b/micro-boot/src/test/java/app/boot/events/com/oath/micro/server/Job.java new file mode 100644 index 000000000..733a8c2ae --- /dev/null +++ b/micro-boot/src/test/java/app/boot/events/com/oath/micro/server/Job.java @@ -0,0 +1,16 @@ +package app.boot.events.com.oath.micro.server; + +import org.springframework.stereotype.Component; + +import com.oath.micro.server.events.ScheduledJob; +import com.oath.micro.server.events.SystemData; + +@Component +public class Job implements ScheduledJob{ + + @Override + public SystemData scheduleAndLog() { + return SystemData.builder().errors(0).processed(2).build(); + } + +} diff --git a/micro-boot/src/test/java/app/boot/events/com/oath/micro/server/Schedular.java b/micro-boot/src/test/java/app/boot/events/com/oath/micro/server/Schedular.java new file mode 100644 index 000000000..a14db58f9 --- /dev/null +++ b/micro-boot/src/test/java/app/boot/events/com/oath/micro/server/Schedular.java @@ -0,0 +1,22 @@ +package app.boot.events.com.oath.micro.server; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + + +@Component +public class Schedular { + + private final Job job; + + @Autowired + public Schedular(final Job job){ + this.job=job; + } + + @Scheduled(fixedDelay=1) + public synchronized void scheduleTask(){ + job.scheduleAndLog(); + } +} diff --git a/micro-boot/src/test/java/app/boot/filter/com/aol/micro/server/AutodiscoveredFilter.java b/micro-boot/src/test/java/app/boot/filter/com/aol/micro/server/AutodiscoveredFilter.java deleted file mode 100644 index ee55011a1..000000000 --- a/micro-boot/src/test/java/app/boot/filter/com/aol/micro/server/AutodiscoveredFilter.java +++ /dev/null @@ -1,49 +0,0 @@ -package app.boot.filter.com.aol.micro.server; - -import java.io.IOException; - -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; - -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.AutoFilterConfiguration; - -import lombok.Getter; - -@Component -public class AutodiscoveredFilter implements AutoFilterConfiguration { - - @Getter - private static volatile int called= 0; - - @Override - public String[] getMapping() { - return new String[] { "/*" }; - } - - @Override - public void init(FilterConfig filterConfig) throws ServletException { - - } - - @Override - public void doFilter(ServletRequest request, ServletResponse response, - FilterChain chain) throws IOException, ServletException { - - called++; - chain.doFilter(request, response); - } - - @Override - public void destroy() { - - - } - - - -} \ No newline at end of file diff --git a/micro-boot/src/test/java/app/boot/filter/com/aol/micro/server/ConfiguredFilter.java b/micro-boot/src/test/java/app/boot/filter/com/aol/micro/server/ConfiguredFilter.java deleted file mode 100644 index 4d64ba4ae..000000000 --- a/micro-boot/src/test/java/app/boot/filter/com/aol/micro/server/ConfiguredFilter.java +++ /dev/null @@ -1,38 +0,0 @@ -package app.boot.filter.com.aol.micro.server; - -import java.io.IOException; - -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; - -import lombok.Getter; - -public class ConfiguredFilter implements Filter { - - @Getter - private static volatile int called= 0; - @Override - public void init(FilterConfig filterConfig) throws ServletException { - // TODO Auto-generated method stub - - } - - @Override - public void doFilter(ServletRequest request, ServletResponse response, - FilterChain chain) throws IOException, ServletException { - called++; - chain.doFilter(request, response); - - } - - @Override - public void destroy() { - // TODO Auto-generated method stub - - } - -} diff --git a/micro-boot/src/test/java/app/boot/filter/com/aol/micro/server/FilterAppLocalMain.java b/micro-boot/src/test/java/app/boot/filter/com/aol/micro/server/FilterAppLocalMain.java deleted file mode 100644 index 42ff0cfaf..000000000 --- a/micro-boot/src/test/java/app/boot/filter/com/aol/micro/server/FilterAppLocalMain.java +++ /dev/null @@ -1,20 +0,0 @@ -package app.boot.filter.com.aol.micro.server; - -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; - -import com.aol.micro.server.MicroserverApp; -@Configuration -@ComponentScan(basePackages = { "app.filter.com.aol.micro.server" }) -public class FilterAppLocalMain { - - - - - public static void main(String[] args) throws InterruptedException { - - new MicroserverApp( FilterAppLocalMain.class, () -> "filter-app") - .run(); - } - - } \ No newline at end of file diff --git a/micro-boot/src/test/java/app/boot/filter/com/aol/micro/server/FilterRunnerTest.java b/micro-boot/src/test/java/app/boot/filter/com/aol/micro/server/FilterRunnerTest.java deleted file mode 100644 index 74497f9e3..000000000 --- a/micro-boot/src/test/java/app/boot/filter/com/aol/micro/server/FilterRunnerTest.java +++ /dev/null @@ -1,59 +0,0 @@ -package app.boot.filter.com.aol.micro.server; - - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.Map; -import java.util.concurrent.ExecutionException; - -import javax.servlet.Filter; - -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.testing.RestAgent; -import com.google.common.collect.ImmutableMap; - -@Ignore -public class FilterRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer(){ - Map filters = ImmutableMap.of("/filter-app/status/ping2",new ConfiguredFilter()); - server = new MicroserverApp( FilterAppLocalMain.class, ConfigurableModule.builder().context("filter-app").filters(filters ).build()); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void testAutoDiscoveredFilter() throws InterruptedException, ExecutionException{ - Thread.sleep(100); - assertThat(AutodiscoveredFilter.getCalled(),is(0)); - assertThat(rest.get("http://localhost:8080/filter-app/status/ping"),is("ok")); - assertThat(AutodiscoveredFilter.getCalled(),is(0)); - } - @Test - public void testConfiguredFilter() throws InterruptedException, ExecutionException{ - Thread.sleep(100); - assertThat(ConfiguredFilter.getCalled(),is(0)); - assertThat(rest.get("http://localhost:8080/filter-app/status/ping2"),is("ok")); - assertThat(ConfiguredFilter.getCalled(),is(1)); - } - - - - -} diff --git a/micro-boot/src/test/java/app/boot/filter/com/aol/micro/server/FilterStatusResource.java b/micro-boot/src/test/java/app/boot/filter/com/aol/micro/server/FilterStatusResource.java deleted file mode 100644 index fccca1ec2..000000000 --- a/micro-boot/src/test/java/app/boot/filter/com/aol/micro/server/FilterStatusResource.java +++ /dev/null @@ -1,30 +0,0 @@ -package app.boot.filter.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.RestResource; - -@Component -@Path("/status") -public class FilterStatusResource implements RestResource { - - - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "ok"; - } - @GET - @Produces("text/plain") - @Path("/ping2") - public String ping2() { - return "ok"; - } - -} \ No newline at end of file diff --git a/micro-boot/src/test/java/app/boot/filter/com/oath/micro/server/AutodiscoveredFilter.java b/micro-boot/src/test/java/app/boot/filter/com/oath/micro/server/AutodiscoveredFilter.java new file mode 100644 index 000000000..7e5aa145e --- /dev/null +++ b/micro-boot/src/test/java/app/boot/filter/com/oath/micro/server/AutodiscoveredFilter.java @@ -0,0 +1,49 @@ +package app.boot.filter.com.oath.micro.server; + +import java.io.IOException; + +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; + +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.AutoFilterConfiguration; + +import lombok.Getter; + +@Component +public class AutodiscoveredFilter implements AutoFilterConfiguration { + + @Getter + private static volatile int called= 0; + + @Override + public String[] getMapping() { + return new String[] { "/*" }; + } + + @Override + public void init(FilterConfig filterConfig) throws ServletException { + + } + + @Override + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + called++; + chain.doFilter(request, response); + } + + @Override + public void destroy() { + + + } + + + +} \ No newline at end of file diff --git a/micro-boot/src/test/java/app/boot/filter/com/oath/micro/server/ConfiguredFilter.java b/micro-boot/src/test/java/app/boot/filter/com/oath/micro/server/ConfiguredFilter.java new file mode 100644 index 000000000..325bf3944 --- /dev/null +++ b/micro-boot/src/test/java/app/boot/filter/com/oath/micro/server/ConfiguredFilter.java @@ -0,0 +1,38 @@ +package app.boot.filter.com.oath.micro.server; + +import java.io.IOException; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; + +import lombok.Getter; + +public class ConfiguredFilter implements Filter { + + @Getter + private static volatile int called= 0; + @Override + public void init(FilterConfig filterConfig) throws ServletException { + // TODO Auto-generated method stub + + } + + @Override + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + called++; + chain.doFilter(request, response); + + } + + @Override + public void destroy() { + // TODO Auto-generated method stub + + } + +} diff --git a/micro-boot/src/test/java/app/boot/filter/com/oath/micro/server/FilterAppLocalMain.java b/micro-boot/src/test/java/app/boot/filter/com/oath/micro/server/FilterAppLocalMain.java new file mode 100644 index 000000000..bbe48664c --- /dev/null +++ b/micro-boot/src/test/java/app/boot/filter/com/oath/micro/server/FilterAppLocalMain.java @@ -0,0 +1,20 @@ +package app.boot.filter.com.oath.micro.server; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +import com.oath.micro.server.MicroserverApp; +@Configuration +@ComponentScan(basePackages = { "app.filter.com.oath.micro.server" }) +public class FilterAppLocalMain { + + + + + public static void main(String[] args) throws InterruptedException { + + new MicroserverApp( FilterAppLocalMain.class, () -> "filter-app") + .run(); + } + + } \ No newline at end of file diff --git a/micro-boot/src/test/java/app/boot/filter/com/oath/micro/server/FilterRunnerTest.java b/micro-boot/src/test/java/app/boot/filter/com/oath/micro/server/FilterRunnerTest.java new file mode 100644 index 000000000..09d56426b --- /dev/null +++ b/micro-boot/src/test/java/app/boot/filter/com/oath/micro/server/FilterRunnerTest.java @@ -0,0 +1,59 @@ +package app.boot.filter.com.oath.micro.server; + + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.Map; +import java.util.concurrent.ExecutionException; + +import javax.servlet.Filter; + +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.module.ConfigurableModule; +import com.oath.micro.server.testing.RestAgent; +import com.google.common.collect.ImmutableMap; + +@Ignore +public class FilterRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer(){ + Map filters = ImmutableMap.of("/filter-app/status/ping2",new ConfiguredFilter()); + server = new MicroserverApp( FilterAppLocalMain.class, ConfigurableModule.builder().context("filter-app").filters(filters ).build()); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void testAutoDiscoveredFilter() throws InterruptedException, ExecutionException{ + Thread.sleep(100); + assertThat(AutodiscoveredFilter.getCalled(),is(0)); + assertThat(rest.get("http://localhost:8080/filter-app/status/ping"),is("ok")); + assertThat(AutodiscoveredFilter.getCalled(),is(0)); + } + @Test + public void testConfiguredFilter() throws InterruptedException, ExecutionException{ + Thread.sleep(100); + assertThat(ConfiguredFilter.getCalled(),is(0)); + assertThat(rest.get("http://localhost:8080/filter-app/status/ping2"),is("ok")); + assertThat(ConfiguredFilter.getCalled(),is(1)); + } + + + + +} diff --git a/micro-boot/src/test/java/app/boot/filter/com/oath/micro/server/FilterStatusResource.java b/micro-boot/src/test/java/app/boot/filter/com/oath/micro/server/FilterStatusResource.java new file mode 100644 index 000000000..1025bae8f --- /dev/null +++ b/micro-boot/src/test/java/app/boot/filter/com/oath/micro/server/FilterStatusResource.java @@ -0,0 +1,30 @@ +package app.boot.filter.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.RestResource; + +@Component +@Path("/status") +public class FilterStatusResource implements RestResource { + + + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "ok"; + } + @GET + @Produces("text/plain") + @Path("/ping2") + public String ping2() { + return "ok"; + } + +} \ No newline at end of file diff --git a/micro-boot/src/test/java/app/guava/com/aol/micro/server/GuavaAppResource.java b/micro-boot/src/test/java/app/guava/com/aol/micro/server/GuavaAppResource.java deleted file mode 100644 index baeb5aed2..000000000 --- a/micro-boot/src/test/java/app/guava/com/aol/micro/server/GuavaAppResource.java +++ /dev/null @@ -1,30 +0,0 @@ -package app.guava.com.aol.micro.server; - -import java.util.List; -import java.util.Optional; - -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.RestResource; -@Component -@Path("/status") -public class GuavaAppResource implements RestResource { - - @POST - @Produces("application/json") - @Path("/ping") - public List ping(ImmutableGuavaEntity entity) { - return entity.getList(); - } - @POST - @Produces("application/json") - @Path("/optional") - public Optional optional(Jdk8Entity entity) { - return entity.getName(); - } - -} diff --git a/micro-boot/src/test/java/app/guava/com/aol/micro/server/GuavaAppTest.java b/micro-boot/src/test/java/app/guava/com/aol/micro/server/GuavaAppTest.java deleted file mode 100644 index c1f87ed92..000000000 --- a/micro-boot/src/test/java/app/guava/com/aol/micro/server/GuavaAppTest.java +++ /dev/null @@ -1,93 +0,0 @@ -package app.guava.com.aol.micro.server; - -import static org.hamcrest.Matchers.hasItem; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - -import java.util.List; -import java.util.Optional; -import java.util.concurrent.ExecutionException; - -import com.oath.cyclops.types.futurestream.SimpleReactStream; -import cyclops.async.SimpleReact; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.boot.config.Microboot; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.rest.jackson.JacksonUtil; -import com.aol.micro.server.testing.RestAgent; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMultimap; -import com.google.common.collect.ImmutableSet; - -@Microserver @Microboot -public class GuavaAppTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - - ImmutableGuavaEntity entity; - Jdk8Entity present; - Jdk8Entity absent; - - SimpleReact simpleReact = new SimpleReact(); - SimpleReactStream stream; - - @Before - public void startServer() { - stream = simpleReact.ofAsync( - () -> server = new MicroserverApp(GuavaAppTest.class, - () -> "guava-app")).then(server -> server.start()); - - entity = ImmutableGuavaEntity.builder().value("value") - .list(ImmutableList.of("hello", "world")) - .mapOfSets(ImmutableMap.of("key1", ImmutableSet.of(1, 2, 3))) - .multiMap(ImmutableMultimap.of("1", 2, "1", 2, "2", 4)).build(); - - JacksonUtil.convertFromJson(JacksonUtil.serializeToJson(entity), - ImmutableGuavaEntity.class); - - present = Jdk8Entity.builder().name(Optional.of("test")).build(); - - JacksonUtil.convertFromJson(JacksonUtil.serializeToJson(present), - Optional.class); - absent = Jdk8Entity.builder().name(Optional.empty()).build(); - } - - @After - public void stopServer() { - server.stop(); - } - - @Test - public void confirmExpectedUrlsPresentTest() throws InterruptedException, - ExecutionException { - - stream.block(); - - assertThat((List) rest.post( - "http://localhost:8080/guava-app/status/ping", entity, - List.class), hasItem("hello")); - - } - - @Test - public void confirmOptionalConversionWorking() throws InterruptedException, - ExecutionException { - - stream.block(); - - assertThat(rest.post("http://localhost:8080/guava-app/status/optional", - present, String.class), is("\"test\"")); - - assertThat(rest.post("http://localhost:8080/guava-app/status/optional", - absent, String.class), is("null")); - - } - -} diff --git a/micro-boot/src/test/java/app/guava/com/aol/micro/server/ImmutableGuavaEntity.java b/micro-boot/src/test/java/app/guava/com/aol/micro/server/ImmutableGuavaEntity.java deleted file mode 100644 index 7c6294547..000000000 --- a/micro-boot/src/test/java/app/guava/com/aol/micro/server/ImmutableGuavaEntity.java +++ /dev/null @@ -1,34 +0,0 @@ -package app.guava.com.aol.micro.server; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Builder; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMultimap; -import com.google.common.collect.ImmutableSet; - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "") -@XmlRootElement(name = "immutable") -@Getter -@AllArgsConstructor -@Builder -public class ImmutableGuavaEntity { - - private final String value; - private final ImmutableList list; - private final ImmutableMap mapOfSets; - private final ImmutableMultimap multiMap; - - public ImmutableGuavaEntity() { - this(null,null,null,null); - } - -} diff --git a/micro-boot/src/test/java/app/guava/com/aol/micro/server/Jdk8Entity.java b/micro-boot/src/test/java/app/guava/com/aol/micro/server/Jdk8Entity.java deleted file mode 100644 index 722e5cafb..000000000 --- a/micro-boot/src/test/java/app/guava/com/aol/micro/server/Jdk8Entity.java +++ /dev/null @@ -1,27 +0,0 @@ -package app.guava.com.aol.micro.server; - -import java.util.Optional; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Builder; - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "") -@XmlRootElement(name = "optional") -@Getter -@AllArgsConstructor -@Builder -public class Jdk8Entity { - - private final Optional name; - - public Jdk8Entity(){ - name = Optional.empty(); - } -} diff --git a/micro-boot/src/test/java/app/guava/com/oath/micro/server/GuavaAppResource.java b/micro-boot/src/test/java/app/guava/com/oath/micro/server/GuavaAppResource.java new file mode 100644 index 000000000..cce09ece4 --- /dev/null +++ b/micro-boot/src/test/java/app/guava/com/oath/micro/server/GuavaAppResource.java @@ -0,0 +1,30 @@ +package app.guava.com.oath.micro.server; + +import java.util.List; +import java.util.Optional; + +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.RestResource; +@Component +@Path("/status") +public class GuavaAppResource implements RestResource { + + @POST + @Produces("application/json") + @Path("/ping") + public List ping(ImmutableGuavaEntity entity) { + return entity.getList(); + } + @POST + @Produces("application/json") + @Path("/optional") + public Optional optional(Jdk8Entity entity) { + return entity.getName(); + } + +} diff --git a/micro-boot/src/test/java/app/guava/com/oath/micro/server/GuavaAppTest.java b/micro-boot/src/test/java/app/guava/com/oath/micro/server/GuavaAppTest.java new file mode 100644 index 000000000..a1247b8be --- /dev/null +++ b/micro-boot/src/test/java/app/guava/com/oath/micro/server/GuavaAppTest.java @@ -0,0 +1,93 @@ +package app.guava.com.oath.micro.server; + +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + +import java.util.List; +import java.util.Optional; +import java.util.concurrent.ExecutionException; + +import com.oath.cyclops.types.futurestream.SimpleReactStream; +import cyclops.async.SimpleReact; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.boot.config.Microboot; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.rest.jackson.JacksonUtil; +import com.oath.micro.server.testing.RestAgent; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableMultimap; +import com.google.common.collect.ImmutableSet; + +@Microserver @Microboot +public class GuavaAppTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + + ImmutableGuavaEntity entity; + Jdk8Entity present; + Jdk8Entity absent; + + SimpleReact simpleReact = new SimpleReact(); + SimpleReactStream stream; + + @Before + public void startServer() { + stream = simpleReact.ofAsync( + () -> server = new MicroserverApp(GuavaAppTest.class, + () -> "guava-app")).then(server -> server.start()); + + entity = ImmutableGuavaEntity.builder().value("value") + .list(ImmutableList.of("hello", "world")) + .mapOfSets(ImmutableMap.of("key1", ImmutableSet.of(1, 2, 3))) + .multiMap(ImmutableMultimap.of("1", 2, "1", 2, "2", 4)).build(); + + JacksonUtil.convertFromJson(JacksonUtil.serializeToJson(entity), + ImmutableGuavaEntity.class); + + present = Jdk8Entity.builder().name(Optional.of("test")).build(); + + JacksonUtil.convertFromJson(JacksonUtil.serializeToJson(present), + Optional.class); + absent = Jdk8Entity.builder().name(Optional.empty()).build(); + } + + @After + public void stopServer() { + server.stop(); + } + + @Test + public void confirmExpectedUrlsPresentTest() throws InterruptedException, + ExecutionException { + + stream.block(); + + assertThat((List) rest.post( + "http://localhost:8080/guava-app/status/ping", entity, + List.class), hasItem("hello")); + + } + + @Test + public void confirmOptionalConversionWorking() throws InterruptedException, + ExecutionException { + + stream.block(); + + assertThat(rest.post("http://localhost:8080/guava-app/status/optional", + present, String.class), is("\"test\"")); + + assertThat(rest.post("http://localhost:8080/guava-app/status/optional", + absent, String.class), is("null")); + + } + +} diff --git a/micro-boot/src/test/java/app/guava/com/oath/micro/server/ImmutableGuavaEntity.java b/micro-boot/src/test/java/app/guava/com/oath/micro/server/ImmutableGuavaEntity.java new file mode 100644 index 000000000..e4e706907 --- /dev/null +++ b/micro-boot/src/test/java/app/guava/com/oath/micro/server/ImmutableGuavaEntity.java @@ -0,0 +1,34 @@ +package app.guava.com.oath.micro.server; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Builder; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableMultimap; +import com.google.common.collect.ImmutableSet; + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "") +@XmlRootElement(name = "immutable") +@Getter +@AllArgsConstructor +@Builder +public class ImmutableGuavaEntity { + + private final String value; + private final ImmutableList list; + private final ImmutableMap mapOfSets; + private final ImmutableMultimap multiMap; + + public ImmutableGuavaEntity() { + this(null,null,null,null); + } + +} diff --git a/micro-boot/src/test/java/app/guava/com/oath/micro/server/Jdk8Entity.java b/micro-boot/src/test/java/app/guava/com/oath/micro/server/Jdk8Entity.java new file mode 100644 index 000000000..df2b8662e --- /dev/null +++ b/micro-boot/src/test/java/app/guava/com/oath/micro/server/Jdk8Entity.java @@ -0,0 +1,27 @@ +package app.guava.com.oath.micro.server; + +import java.util.Optional; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Builder; + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "") +@XmlRootElement(name = "optional") +@Getter +@AllArgsConstructor +@Builder +public class Jdk8Entity { + + private final Optional name; + + public Jdk8Entity(){ + name = Optional.empty(); + } +} diff --git a/micro-boot/src/test/java/app/listeners/com/aol/micro/server/AutodiscoveredListener.java b/micro-boot/src/test/java/app/listeners/com/aol/micro/server/AutodiscoveredListener.java deleted file mode 100644 index c2d92407e..000000000 --- a/micro-boot/src/test/java/app/listeners/com/aol/micro/server/AutodiscoveredListener.java +++ /dev/null @@ -1,45 +0,0 @@ -package app.listeners.com.aol.micro.server; - -import java.io.IOException; - -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; - -import lombok.Getter; - -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.FilterConfiguration; - -@Component -public class AutodiscoveredListener implements ServletContextListener { - - @Getter - private static volatile int called= 0; - - @Override - public void contextInitialized(ServletContextEvent sce) { - called ++; - - } - - @Override - public void contextDestroyed(ServletContextEvent sce) { - - - } - - - - - - - - -} \ No newline at end of file diff --git a/micro-boot/src/test/java/app/listeners/com/aol/micro/server/ListenerRunnerTest.java b/micro-boot/src/test/java/app/listeners/com/aol/micro/server/ListenerRunnerTest.java deleted file mode 100644 index ba6591048..000000000 --- a/micro-boot/src/test/java/app/listeners/com/aol/micro/server/ListenerRunnerTest.java +++ /dev/null @@ -1,56 +0,0 @@ -package app.listeners.com.aol.micro.server; - - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.List; -import java.util.concurrent.ExecutionException; - -import javax.servlet.ServletContextListener; - -import nonautoscan.com.aol.micro.server.ConfiguredListener; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.boot.config.Microboot; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.testing.RestAgent; -import com.google.common.collect.ImmutableList; - - -@Microserver @Microboot -public class ListenerRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer(){ - List listeners = ImmutableList.of(new ConfiguredListener()); - server = new MicroserverApp( ListenerRunnerTest.class, ConfigurableModule.builder().context("listener-app").listeners(listeners ).build()); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void testListeners() throws InterruptedException, ExecutionException{ - - assertThat(AutodiscoveredListener.getCalled(),is(1)); - assertThat(ConfiguredListener.getCalled(),is(1)); - } - - - - - -} diff --git a/micro-boot/src/test/java/app/listeners/com/oath/micro/server/AutodiscoveredListener.java b/micro-boot/src/test/java/app/listeners/com/oath/micro/server/AutodiscoveredListener.java new file mode 100644 index 000000000..a3dfdff21 --- /dev/null +++ b/micro-boot/src/test/java/app/listeners/com/oath/micro/server/AutodiscoveredListener.java @@ -0,0 +1,35 @@ +package app.listeners.com.oath.micro.server; + +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; + +import lombok.Getter; + +import org.springframework.stereotype.Component; + +@Component +public class AutodiscoveredListener implements ServletContextListener { + + @Getter + private static volatile int called= 0; + + @Override + public void contextInitialized(ServletContextEvent sce) { + called ++; + + } + + @Override + public void contextDestroyed(ServletContextEvent sce) { + + + } + + + + + + + + +} \ No newline at end of file diff --git a/micro-boot/src/test/java/app/listeners/com/oath/micro/server/ListenerRunnerTest.java b/micro-boot/src/test/java/app/listeners/com/oath/micro/server/ListenerRunnerTest.java new file mode 100644 index 000000000..c72304ea1 --- /dev/null +++ b/micro-boot/src/test/java/app/listeners/com/oath/micro/server/ListenerRunnerTest.java @@ -0,0 +1,56 @@ +package app.listeners.com.oath.micro.server; + + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.List; +import java.util.concurrent.ExecutionException; + +import javax.servlet.ServletContextListener; + +import nonautoscan.com.oath.micro.server.ConfiguredListener; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.boot.config.Microboot; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.module.ConfigurableModule; +import com.oath.micro.server.testing.RestAgent; +import com.google.common.collect.ImmutableList; + + +@Microserver @Microboot +public class ListenerRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer(){ + List listeners = ImmutableList.of(new ConfiguredListener()); + server = new MicroserverApp( ListenerRunnerTest.class, ConfigurableModule.builder().context("listener-app").listeners(listeners ).build()); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void testListeners() throws InterruptedException, ExecutionException{ + + assertThat(AutodiscoveredListener.getCalled(),is(1)); + assertThat(ConfiguredListener.getCalled(),is(1)); + } + + + + + +} diff --git a/micro-boot/src/test/java/app/metrics/boot/com/aol/micro/server/MetricsRunnerTest.java b/micro-boot/src/test/java/app/metrics/boot/com/aol/micro/server/MetricsRunnerTest.java deleted file mode 100644 index ec2cca159..000000000 --- a/micro-boot/src/test/java/app/metrics/boot/com/aol/micro/server/MetricsRunnerTest.java +++ /dev/null @@ -1,59 +0,0 @@ -package app.metrics.boot.com.aol.micro.server; - - -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - -import java.io.IOException; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.boot.config.Microboot; -import com.aol.micro.server.spring.metrics.CodahaleMetricsConfigurer; -import com.aol.micro.server.testing.RestAgent; - -@Microboot -public class MetricsRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer(){ - CodahaleMetricsConfigurer.setInit( metricRegistry -> TestReporter - .forRegistry(metricRegistry) - .build() - .start(10, TimeUnit.MILLISECONDS)); - - server = new MicroserverApp( ()-> "simple-app"); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException, IOException{ - - - - - - assertThat(rest.get("http://localhost:8080/simple-app/metrics/ping"),is("ok")); - - - assertThat(TestReporter.getTimer().size(),greaterThan(0)); - } - - - -} diff --git a/micro-boot/src/test/java/app/metrics/boot/com/aol/micro/server/MetricsStatusResource.java b/micro-boot/src/test/java/app/metrics/boot/com/aol/micro/server/MetricsStatusResource.java deleted file mode 100644 index 48bd138ee..000000000 --- a/micro-boot/src/test/java/app/metrics/boot/com/aol/micro/server/MetricsStatusResource.java +++ /dev/null @@ -1,28 +0,0 @@ -package app.metrics.boot.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - - - -import com.aol.micro.server.auto.discovery.RestResource; - -@Component -@Path("/metrics") -public class MetricsStatusResource implements RestResource { - - @Autowired - TimedResource timed; - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - timed.times(); - return "ok"; - } - -} \ No newline at end of file diff --git a/micro-boot/src/test/java/app/metrics/boot/com/aol/micro/server/TestReporter.java b/micro-boot/src/test/java/app/metrics/boot/com/aol/micro/server/TestReporter.java deleted file mode 100644 index a75b93ca4..000000000 --- a/micro-boot/src/test/java/app/metrics/boot/com/aol/micro/server/TestReporter.java +++ /dev/null @@ -1,169 +0,0 @@ -package app.metrics.boot.com.aol.micro.server; - -import java.io.PrintStream; -import java.util.Locale; -import java.util.SortedMap; -import java.util.TimeZone; -import java.util.TreeMap; -import java.util.concurrent.TimeUnit; - -import lombok.Getter; - -import com.codahale.metrics.Clock; -import com.codahale.metrics.ConsoleReporter; -import com.codahale.metrics.Counter; -import com.codahale.metrics.Gauge; -import com.codahale.metrics.Histogram; -import com.codahale.metrics.Meter; -import com.codahale.metrics.MetricFilter; -import com.codahale.metrics.MetricRegistry; -import com.codahale.metrics.ScheduledReporter; -import com.codahale.metrics.Timer; - - -public class TestReporter extends ScheduledReporter { - - @Getter - private static volatile SortedMap timer = new TreeMap<>(); - - protected TestReporter(MetricRegistry registry, String name, - MetricFilter filter, TimeUnit rateUnit, TimeUnit durationUnit) { - super(registry, name, filter, rateUnit, durationUnit); - - } - - - public static Builder forRegistry(MetricRegistry registry) { - return new Builder(registry); - } - - @Override - public void report(SortedMap gauges, - SortedMap counters, - SortedMap histograms, - SortedMap meters, SortedMap timers) { - this.timer = timers; - - - } - - public static class Builder { - private final MetricRegistry registry; - private PrintStream output; - private Locale locale; - private Clock clock; - private TimeZone timeZone; - private TimeUnit rateUnit; - private TimeUnit durationUnit; - private MetricFilter filter; - - private Builder(MetricRegistry registry) { - this.registry = registry; - this.output = System.out; - this.locale = Locale.getDefault(); - this.clock = Clock.defaultClock(); - this.timeZone = TimeZone.getDefault(); - this.rateUnit = TimeUnit.SECONDS; - this.durationUnit = TimeUnit.MILLISECONDS; - this.filter = MetricFilter.ALL; - } - - /** - * Write to the given {@link PrintStream}. - * - * @param output a {@link PrintStream} instance. - * @return {@code this} - */ - public Builder outputTo(PrintStream output) { - this.output = output; - return this; - } - - /** - * Format numbers for the given {@link Locale}. - * - * @param locale a {@link Locale} - * @return {@code this} - */ - public Builder formattedFor(Locale locale) { - this.locale = locale; - return this; - } - - /** - * Use the given {@link Clock} instance for the time. - * - * @param clock a {@link Clock} instance - * @return {@code this} - */ - public Builder withClock(Clock clock) { - this.clock = clock; - return this; - } - - /** - * Use the given {@link TimeZone} for the time. - * - * @param timeZone a {@link TimeZone} - * @return {@code this} - */ - public Builder formattedFor(TimeZone timeZone) { - this.timeZone = timeZone; - return this; - } - - /** - * Convert rates to the given time unit. - * - * @param rateUnit a unit of time - * @return {@code this} - */ - public Builder convertRatesTo(TimeUnit rateUnit) { - this.rateUnit = rateUnit; - return this; - } - - /** - * Convert durations to the given time unit. - * - * @param durationUnit a unit of time - * @return {@code this} - */ - public Builder convertDurationsTo(TimeUnit durationUnit) { - this.durationUnit = durationUnit; - return this; - } - - /** - * Only report metrics which match the given filter. - * - * @param filter a {@link MetricFilter} - * @return {@code this} - */ - public Builder filter(MetricFilter filter) { - this.filter = filter; - return this; - } - - /** - * Builds a {@link ConsoleReporter} with the given properties. - * - * @return a {@link ConsoleReporter} - */ - public TestReporter build() { - return new TestReporter(registry, - // output, - "name", - // locale, - // clock, - // timeZone, - this.filter, - rateUnit, - durationUnit - ); - } - } - - -} - diff --git a/micro-boot/src/test/java/app/metrics/boot/com/aol/micro/server/TimedResource.java b/micro-boot/src/test/java/app/metrics/boot/com/aol/micro/server/TimedResource.java deleted file mode 100644 index af197479b..000000000 --- a/micro-boot/src/test/java/app/metrics/boot/com/aol/micro/server/TimedResource.java +++ /dev/null @@ -1,17 +0,0 @@ -package app.metrics.boot.com.aol.micro.server; - -import org.springframework.stereotype.Component; - -import com.codahale.metrics.annotation.Timed; -import com.ryantenney.metrics.annotation.Counted; - -@Component -public class TimedResource { - - - @Timed - public String times(){ - - return "ok!"; - } -} diff --git a/micro-boot/src/test/java/app/metrics/boot/com/oath/micro/server/MetricsRunnerTest.java b/micro-boot/src/test/java/app/metrics/boot/com/oath/micro/server/MetricsRunnerTest.java new file mode 100644 index 000000000..df9410e6b --- /dev/null +++ b/micro-boot/src/test/java/app/metrics/boot/com/oath/micro/server/MetricsRunnerTest.java @@ -0,0 +1,59 @@ +package app.metrics.boot.com.oath.micro.server; + + +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + +import java.io.IOException; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.boot.config.Microboot; +import com.oath.micro.server.spring.metrics.CodahaleMetricsConfigurer; +import com.oath.micro.server.testing.RestAgent; + +@Microboot +public class MetricsRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer(){ + CodahaleMetricsConfigurer.setInit( metricRegistry -> TestReporter + .forRegistry(metricRegistry) + .build() + .start(10, TimeUnit.MILLISECONDS)); + + server = new MicroserverApp( ()-> "simple-app"); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException, IOException{ + + + + + + assertThat(rest.get("http://localhost:8080/simple-app/metrics/ping"),is("ok")); + + + assertThat(TestReporter.getTimer().size(),greaterThan(0)); + } + + + +} diff --git a/micro-boot/src/test/java/app/metrics/boot/com/oath/micro/server/MetricsStatusResource.java b/micro-boot/src/test/java/app/metrics/boot/com/oath/micro/server/MetricsStatusResource.java new file mode 100644 index 000000000..c7389afdd --- /dev/null +++ b/micro-boot/src/test/java/app/metrics/boot/com/oath/micro/server/MetricsStatusResource.java @@ -0,0 +1,28 @@ +package app.metrics.boot.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + + + +import com.oath.micro.server.auto.discovery.RestResource; + +@Component +@Path("/metrics") +public class MetricsStatusResource implements RestResource { + + @Autowired + TimedResource timed; + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + timed.times(); + return "ok"; + } + +} \ No newline at end of file diff --git a/micro-boot/src/test/java/app/metrics/boot/com/oath/micro/server/TestReporter.java b/micro-boot/src/test/java/app/metrics/boot/com/oath/micro/server/TestReporter.java new file mode 100644 index 000000000..8c69aa2e3 --- /dev/null +++ b/micro-boot/src/test/java/app/metrics/boot/com/oath/micro/server/TestReporter.java @@ -0,0 +1,169 @@ +package app.metrics.boot.com.oath.micro.server; + +import java.io.PrintStream; +import java.util.Locale; +import java.util.SortedMap; +import java.util.TimeZone; +import java.util.TreeMap; +import java.util.concurrent.TimeUnit; + +import lombok.Getter; + +import com.codahale.metrics.Clock; +import com.codahale.metrics.ConsoleReporter; +import com.codahale.metrics.Counter; +import com.codahale.metrics.Gauge; +import com.codahale.metrics.Histogram; +import com.codahale.metrics.Meter; +import com.codahale.metrics.MetricFilter; +import com.codahale.metrics.MetricRegistry; +import com.codahale.metrics.ScheduledReporter; +import com.codahale.metrics.Timer; + + +public class TestReporter extends ScheduledReporter { + + @Getter + private static volatile SortedMap timer = new TreeMap<>(); + + protected TestReporter(MetricRegistry registry, String name, + MetricFilter filter, TimeUnit rateUnit, TimeUnit durationUnit) { + super(registry, name, filter, rateUnit, durationUnit); + + } + + + public static Builder forRegistry(MetricRegistry registry) { + return new Builder(registry); + } + + @Override + public void report(SortedMap gauges, + SortedMap counters, + SortedMap histograms, + SortedMap meters, SortedMap timers) { + this.timer = timers; + + + } + + public static class Builder { + private final MetricRegistry registry; + private PrintStream output; + private Locale locale; + private Clock clock; + private TimeZone timeZone; + private TimeUnit rateUnit; + private TimeUnit durationUnit; + private MetricFilter filter; + + private Builder(MetricRegistry registry) { + this.registry = registry; + this.output = System.out; + this.locale = Locale.getDefault(); + this.clock = Clock.defaultClock(); + this.timeZone = TimeZone.getDefault(); + this.rateUnit = TimeUnit.SECONDS; + this.durationUnit = TimeUnit.MILLISECONDS; + this.filter = MetricFilter.ALL; + } + + /** + * Write to the given {@link PrintStream}. + * + * @param output a {@link PrintStream} instance. + * @return {@code this} + */ + public Builder outputTo(PrintStream output) { + this.output = output; + return this; + } + + /** + * Format numbers for the given {@link Locale}. + * + * @param locale a {@link Locale} + * @return {@code this} + */ + public Builder formattedFor(Locale locale) { + this.locale = locale; + return this; + } + + /** + * Use the given {@link Clock} instance for the time. + * + * @param clock a {@link Clock} instance + * @return {@code this} + */ + public Builder withClock(Clock clock) { + this.clock = clock; + return this; + } + + /** + * Use the given {@link TimeZone} for the time. + * + * @param timeZone a {@link TimeZone} + * @return {@code this} + */ + public Builder formattedFor(TimeZone timeZone) { + this.timeZone = timeZone; + return this; + } + + /** + * Convert rates to the given time unit. + * + * @param rateUnit a unit of time + * @return {@code this} + */ + public Builder convertRatesTo(TimeUnit rateUnit) { + this.rateUnit = rateUnit; + return this; + } + + /** + * Convert durations to the given time unit. + * + * @param durationUnit a unit of time + * @return {@code this} + */ + public Builder convertDurationsTo(TimeUnit durationUnit) { + this.durationUnit = durationUnit; + return this; + } + + /** + * Only report metrics which match the given filter. + * + * @param filter a {@link MetricFilter} + * @return {@code this} + */ + public Builder filter(MetricFilter filter) { + this.filter = filter; + return this; + } + + /** + * Builds a {@link ConsoleReporter} with the given properties. + * + * @return a {@link ConsoleReporter} + */ + public TestReporter build() { + return new TestReporter(registry, + // output, + "name", + // locale, + // clock, + // timeZone, + this.filter, + rateUnit, + durationUnit + ); + } + } + + +} + diff --git a/micro-boot/src/test/java/app/metrics/boot/com/oath/micro/server/TimedResource.java b/micro-boot/src/test/java/app/metrics/boot/com/oath/micro/server/TimedResource.java new file mode 100644 index 000000000..efafe3099 --- /dev/null +++ b/micro-boot/src/test/java/app/metrics/boot/com/oath/micro/server/TimedResource.java @@ -0,0 +1,16 @@ +package app.metrics.boot.com.oath.micro.server; + +import org.springframework.stereotype.Component; + +import com.codahale.metrics.annotation.Timed; + +@Component +public class TimedResource { + + + @Timed + public String times(){ + + return "ok!"; + } +} diff --git a/micro-boot/src/test/java/app/minimal/com/aol/micro/server/MinimalClassTest.java b/micro-boot/src/test/java/app/minimal/com/aol/micro/server/MinimalClassTest.java deleted file mode 100644 index 2ddc53508..000000000 --- a/micro-boot/src/test/java/app/minimal/com/aol/micro/server/MinimalClassTest.java +++ /dev/null @@ -1,57 +0,0 @@ -package app.minimal.com.aol.micro.server; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.testing.RestAgent; - -@Rest -@Path("/single") -public class MinimalClassTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer(){ - - server = new MicroserverApp(()-> "minimal-app"); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - - - assertThat(rest.get("http://localhost:8080/minimal-app/single/ping"),is("ok1")); - - } - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "ok1"; - } - - -} \ No newline at end of file diff --git a/micro-boot/src/test/java/app/minimal/com/oath/micro/server/MinimalClassTest.java b/micro-boot/src/test/java/app/minimal/com/oath/micro/server/MinimalClassTest.java new file mode 100644 index 000000000..68475d3fb --- /dev/null +++ b/micro-boot/src/test/java/app/minimal/com/oath/micro/server/MinimalClassTest.java @@ -0,0 +1,57 @@ +package app.minimal.com.oath.micro.server; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.auto.discovery.Rest; +import com.oath.micro.server.testing.RestAgent; + +@Rest +@Path("/single") +public class MinimalClassTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer(){ + + server = new MicroserverApp(()-> "minimal-app"); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + + + assertThat(rest.get("http://localhost:8080/minimal-app/single/ping"),is("ok1")); + + } + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "ok1"; + } + + +} \ No newline at end of file diff --git a/micro-boot/src/test/java/app/rest/client/com/aol/micro/server/GenericRestClientResource.java b/micro-boot/src/test/java/app/rest/client/com/aol/micro/server/GenericRestClientResource.java deleted file mode 100644 index 8aa6fdec9..000000000 --- a/micro-boot/src/test/java/app/rest/client/com/aol/micro/server/GenericRestClientResource.java +++ /dev/null @@ -1,56 +0,0 @@ -package app.rest.client.com.aol.micro.server; - -import java.util.List; - -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.RestResource; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; - -@Component -@Path("/rest") -public class GenericRestClientResource implements RestResource { - - - @GET - @Produces("application/json") - @Path("/get") - public List get() { - - return ImmutableList.of("ok"); - } - - @POST - @Produces("application/json") - @Path("/post") - public ImmutableSet post(ImmutableMap map) { - - return ImmutableSet.copyOf(map.values()); - } - - @PUT - @Produces("application/json") - @Path("/put") - public ImmutableSet put(ImmutableMap map) { - - return ImmutableSet.copyOf(map.values()); - } - @DELETE - @Produces("application/json") - @Path("/delete") - public List delete(ImmutableMap map) { - - return ImmutableList.of("ok"); - } - - -} \ No newline at end of file diff --git a/micro-boot/src/test/java/app/rest/client/com/aol/micro/server/MyEntity.java b/micro-boot/src/test/java/app/rest/client/com/aol/micro/server/MyEntity.java deleted file mode 100644 index 1d2fa9b71..000000000 --- a/micro-boot/src/test/java/app/rest/client/com/aol/micro/server/MyEntity.java +++ /dev/null @@ -1,12 +0,0 @@ -package app.rest.client.com.aol.micro.server; - -import lombok.EqualsAndHashCode; -import lombok.Getter; - -@EqualsAndHashCode -@Getter -public class MyEntity { - - private final String name ="myEntity"; - -} diff --git a/micro-boot/src/test/java/app/rest/client/com/aol/micro/server/RestClientResource.java b/micro-boot/src/test/java/app/rest/client/com/aol/micro/server/RestClientResource.java deleted file mode 100644 index c784b47d7..000000000 --- a/micro-boot/src/test/java/app/rest/client/com/aol/micro/server/RestClientResource.java +++ /dev/null @@ -1,54 +0,0 @@ -package app.rest.client.com.aol.micro.server; - -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.RestResource; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; - -@Component -@Path("/generics") -public class RestClientResource implements RestResource { - - private final ImmutableList result = ImmutableList.of(new MyEntity()); - @GET - @Produces("application/json") - @Path("/get") - public ImmutableList get() { - - return result; - } - - @POST - @Produces("application/json") - @Path("/post") - public ImmutableList post(ImmutableMap map) { - - return result; - } - - @PUT - @Produces("application/json") - @Path("/put") - public ImmutableList put(ImmutableMap map) { - - return result; - } - @DELETE - @Produces("application/json") - @Path("/delete") - public ImmutableList delete(ImmutableMap map) { - - return result; - } - - -} \ No newline at end of file diff --git a/micro-boot/src/test/java/app/rest/client/com/aol/micro/server/RestClientTest.java b/micro-boot/src/test/java/app/rest/client/com/aol/micro/server/RestClientTest.java deleted file mode 100644 index 52d925a6e..000000000 --- a/micro-boot/src/test/java/app/rest/client/com/aol/micro/server/RestClientTest.java +++ /dev/null @@ -1,115 +0,0 @@ - -package app.rest.client.com.aol.micro.server; - - -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.assertThat; - -import java.net.URI; -import java.net.URISyntaxException; -import java.util.List; -import java.util.concurrent.ExecutionException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.springframework.core.ParameterizedTypeReference; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpMethod; -import org.springframework.web.client.RestClientException; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.boot.config.Microboot; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.rest.client.nio.AsyncRestClient; -import com.aol.micro.server.rest.client.nio.NIORestClient; -import com.aol.micro.server.rest.client.nio.SpringConfig; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; - -@Microserver @Microboot -public class RestClientTest { - - private final AsyncRestClient> listClient = new AsyncRestClient(1000,1000).withResponse(List.class); - private final AsyncRestClient> setClient = new AsyncRestClient(1000,1000).withResponse(ImmutableSet.class);; - private final AsyncRestClient> genericsClient = new AsyncRestClient(1000,1000).withGenericResponse(ImmutableList.class, MyEntity.class); - - private final NIORestClient rest = new SpringConfig().restClient(); - - - MicroserverApp server; - @Before - public void startServer(){ - - server = new MicroserverApp( RestClientTest.class, ()-> "rest-app"); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - /* - * Simpler with JaxRsNIOClient - */ - @Test - public void testCRUD() throws InterruptedException, ExecutionException{ - - - assertThat(listClient.get("http://localhost:8080/rest-app/rest/get").get().get(0),is("ok")); - assertThat(setClient.post("http://localhost:8080/rest-app/rest/post",ImmutableMap.of(1,"hello")).get(),is(ImmutableSet.of("hello"))); - assertThat(setClient.put("http://localhost:8080/rest-app/rest/put",ImmutableMap.of(1,"hello")).get(),is(ImmutableSet.of("hello"))); - assertThat(listClient.delete("http://localhost:8080/rest-app/rest/delete").get().get(0),is("ok")); - } - - @Test - public void testCRUDGenerics() throws InterruptedException, ExecutionException{ - - - assertThat(genericsClient.get("http://localhost:8080/rest-app/generics/get").get().get(0),is(new MyEntity())); - assertThat(genericsClient.post("http://localhost:8080/rest-app/generics/post",ImmutableMap.of(1,"hello")).get(),is(ImmutableList.of(new MyEntity()))); - assertThat(genericsClient.put("http://localhost:8080/rest-app/generics/put",ImmutableMap.of(1,"hello")).get(),is(ImmutableList.of(new MyEntity()))); - assertThat(genericsClient.delete("http://localhost:8080/rest-app/generics/delete").get().get(0),is(new MyEntity())); - } - - /** - * More complex with Spring REST Template Based NIORestTemplate - * - */ - - @Test - public void testCRUDSpring() throws InterruptedException, ExecutionException, RestClientException, URISyntaxException{ - - - assertThat(rest.getForEntity(new URI("http://localhost:8080/rest-app/rest/get"),List.class).get().getBody().get(0),is("ok")); - - assertThat(rest.postForEntity("http://localhost:8080/rest-app/rest/post", new HttpEntity(ImmutableMap.of(1,"hello")), ImmutableSet.class).get().getBody(),is(ImmutableSet.of("hello"))); - assertThat( rest.put("http://localhost:8080/rest-app/rest/put",new HttpEntity(ImmutableMap.of(1,"hello")),ImmutableSet.class).get() - ,is(nullValue())); - assertThat(rest.delete("http://localhost:8080/rest-app/rest/delete").get(),is(nullValue())); - } - - @Test - public void testCRUDGenericsSpring() throws InterruptedException, ExecutionException{ - - - assertThat(rest.exchange("http://localhost:8080/rest-app/generics/get",HttpMethod.GET,null,new ParameterizedTypeReference>(){}) - .get().getBody().get(0),is(new MyEntity())); - - assertThat(rest.exchange("http://localhost:8080/rest-app/generics/post",HttpMethod.POST,new HttpEntity(ImmutableMap.of(1,"hello")),new ParameterizedTypeReference>(){}) - .get().getBody(),is(ImmutableList.of(new MyEntity()))); - - assertThat(rest.exchange("http://localhost:8080/rest-app/generics/put",HttpMethod.PUT,new HttpEntity(ImmutableMap.of(1,"hello")),new ParameterizedTypeReference>(){}) - .get().getBody(),is(ImmutableList.of(new MyEntity()))); - - assertThat(rest.exchange("http://localhost:8080/rest-app/generics/delete",HttpMethod.DELETE,null,new ParameterizedTypeReference>(){}) - .get().getBody().get(0),is(new MyEntity())); - - } - - - -} diff --git a/micro-boot/src/test/java/app/rest/client/com/oath/micro/server/GenericRestClientResource.java b/micro-boot/src/test/java/app/rest/client/com/oath/micro/server/GenericRestClientResource.java new file mode 100644 index 000000000..3b6b9ee90 --- /dev/null +++ b/micro-boot/src/test/java/app/rest/client/com/oath/micro/server/GenericRestClientResource.java @@ -0,0 +1,56 @@ +package app.rest.client.com.oath.micro.server; + +import java.util.List; + +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.RestResource; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; + +@Component +@Path("/rest") +public class GenericRestClientResource implements RestResource { + + + @GET + @Produces("application/json") + @Path("/get") + public List get() { + + return ImmutableList.of("ok"); + } + + @POST + @Produces("application/json") + @Path("/post") + public ImmutableSet post(ImmutableMap map) { + + return ImmutableSet.copyOf(map.values()); + } + + @PUT + @Produces("application/json") + @Path("/put") + public ImmutableSet put(ImmutableMap map) { + + return ImmutableSet.copyOf(map.values()); + } + @DELETE + @Produces("application/json") + @Path("/delete") + public List delete(ImmutableMap map) { + + return ImmutableList.of("ok"); + } + + +} \ No newline at end of file diff --git a/micro-boot/src/test/java/app/rest/client/com/oath/micro/server/MyEntity.java b/micro-boot/src/test/java/app/rest/client/com/oath/micro/server/MyEntity.java new file mode 100644 index 000000000..c075fa67f --- /dev/null +++ b/micro-boot/src/test/java/app/rest/client/com/oath/micro/server/MyEntity.java @@ -0,0 +1,12 @@ +package app.rest.client.com.oath.micro.server; + +import lombok.EqualsAndHashCode; +import lombok.Getter; + +@EqualsAndHashCode +@Getter +public class MyEntity { + + private final String name ="myEntity"; + +} diff --git a/micro-boot/src/test/java/app/rest/client/com/oath/micro/server/RestClientResource.java b/micro-boot/src/test/java/app/rest/client/com/oath/micro/server/RestClientResource.java new file mode 100644 index 000000000..90c119ba5 --- /dev/null +++ b/micro-boot/src/test/java/app/rest/client/com/oath/micro/server/RestClientResource.java @@ -0,0 +1,53 @@ +package app.rest.client.com.oath.micro.server; + +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.RestResource; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; + +@Component +@Path("/generics") +public class RestClientResource implements RestResource { + + private final ImmutableList result = ImmutableList.of(new MyEntity()); + @GET + @Produces("application/json") + @Path("/get") + public ImmutableList get() { + + return result; + } + + @POST + @Produces("application/json") + @Path("/post") + public ImmutableList post(ImmutableMap map) { + + return result; + } + + @PUT + @Produces("application/json") + @Path("/put") + public ImmutableList put(ImmutableMap map) { + + return result; + } + @DELETE + @Produces("application/json") + @Path("/delete") + public ImmutableList delete(ImmutableMap map) { + + return result; + } + + +} \ No newline at end of file diff --git a/micro-boot/src/test/java/app/rest/client/com/oath/micro/server/RestClientTest.java b/micro-boot/src/test/java/app/rest/client/com/oath/micro/server/RestClientTest.java new file mode 100644 index 000000000..f456a0271 --- /dev/null +++ b/micro-boot/src/test/java/app/rest/client/com/oath/micro/server/RestClientTest.java @@ -0,0 +1,115 @@ + +package app.rest.client.com.oath.micro.server; + + +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.assertThat; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.List; +import java.util.concurrent.ExecutionException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpMethod; +import org.springframework.web.client.RestClientException; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.boot.config.Microboot; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.rest.client.nio.AsyncRestClient; +import com.oath.micro.server.rest.client.nio.NIORestClient; +import com.oath.micro.server.rest.client.nio.SpringConfig; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; + +@Microserver @Microboot +public class RestClientTest { + + private final AsyncRestClient> listClient = new AsyncRestClient(1000,1000).withResponse(List.class); + private final AsyncRestClient> setClient = new AsyncRestClient(1000,1000).withResponse(ImmutableSet.class);; + private final AsyncRestClient> genericsClient = new AsyncRestClient(1000,1000).withGenericResponse(ImmutableList.class, MyEntity.class); + + private final NIORestClient rest = new SpringConfig().restClient(); + + + MicroserverApp server; + @Before + public void startServer(){ + + server = new MicroserverApp( RestClientTest.class, ()-> "rest-app"); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + /* + * Simpler with JaxRsNIOClient + */ + @Test + public void testCRUD() throws InterruptedException, ExecutionException{ + + + assertThat(listClient.get("http://localhost:8080/rest-app/rest/get").get().get(0),is("ok")); + assertThat(setClient.post("http://localhost:8080/rest-app/rest/post",ImmutableMap.of(1,"hello")).get(),is(ImmutableSet.of("hello"))); + assertThat(setClient.put("http://localhost:8080/rest-app/rest/put",ImmutableMap.of(1,"hello")).get(),is(ImmutableSet.of("hello"))); + assertThat(listClient.delete("http://localhost:8080/rest-app/rest/delete").get().get(0),is("ok")); + } + + @Test + public void testCRUDGenerics() throws InterruptedException, ExecutionException{ + + + assertThat(genericsClient.get("http://localhost:8080/rest-app/generics/get").get().get(0),is(new MyEntity())); + assertThat(genericsClient.post("http://localhost:8080/rest-app/generics/post",ImmutableMap.of(1,"hello")).get(),is(ImmutableList.of(new MyEntity()))); + assertThat(genericsClient.put("http://localhost:8080/rest-app/generics/put",ImmutableMap.of(1,"hello")).get(),is(ImmutableList.of(new MyEntity()))); + assertThat(genericsClient.delete("http://localhost:8080/rest-app/generics/delete").get().get(0),is(new MyEntity())); + } + + /** + * More complex with Spring REST Template Based NIORestTemplate + * + */ + + @Test + public void testCRUDSpring() throws InterruptedException, ExecutionException, RestClientException, URISyntaxException{ + + + assertThat(rest.getForEntity(new URI("http://localhost:8080/rest-app/rest/get"),List.class).get().getBody().get(0),is("ok")); + + assertThat(rest.postForEntity("http://localhost:8080/rest-app/rest/post", new HttpEntity(ImmutableMap.of(1,"hello")), ImmutableSet.class).get().getBody(),is(ImmutableSet.of("hello"))); + assertThat( rest.put("http://localhost:8080/rest-app/rest/put",new HttpEntity(ImmutableMap.of(1,"hello")),ImmutableSet.class).get() + ,is(nullValue())); + assertThat(rest.delete("http://localhost:8080/rest-app/rest/delete").get(),is(nullValue())); + } + + @Test + public void testCRUDGenericsSpring() throws InterruptedException, ExecutionException{ + + + assertThat(rest.exchange("http://localhost:8080/rest-app/generics/get",HttpMethod.GET,null,new ParameterizedTypeReference>(){}) + .get().getBody().get(0),is(new MyEntity())); + + assertThat(rest.exchange("http://localhost:8080/rest-app/generics/post",HttpMethod.POST,new HttpEntity(ImmutableMap.of(1,"hello")),new ParameterizedTypeReference>(){}) + .get().getBody(),is(ImmutableList.of(new MyEntity()))); + + assertThat(rest.exchange("http://localhost:8080/rest-app/generics/put",HttpMethod.PUT,new HttpEntity(ImmutableMap.of(1,"hello")),new ParameterizedTypeReference>(){}) + .get().getBody(),is(ImmutableList.of(new MyEntity()))); + + assertThat(rest.exchange("http://localhost:8080/rest-app/generics/delete",HttpMethod.DELETE,null,new ParameterizedTypeReference>(){}) + .get().getBody().get(0),is(new MyEntity())); + + } + + + +} diff --git a/micro-boot/src/test/java/app/servlet/com/aol/micro/server/AppRunnerLocalMain.java b/micro-boot/src/test/java/app/servlet/com/aol/micro/server/AppRunnerLocalMain.java deleted file mode 100644 index b447491a1..000000000 --- a/micro-boot/src/test/java/app/servlet/com/aol/micro/server/AppRunnerLocalMain.java +++ /dev/null @@ -1,20 +0,0 @@ -package app.servlet.com.aol.micro.server; - - -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; - -import com.aol.micro.server.MicroserverApp; - -@Configuration -@ComponentScan(basePackages = { "app.servlet.com.aol.micro.server" }) -public class AppRunnerLocalMain { - - - public static void main(String[] args) throws InterruptedException { - - new MicroserverApp( AppRunnerLocalMain.class, () -> "test-app") - .run(); - } - -} diff --git a/micro-boot/src/test/java/app/servlet/com/aol/micro/server/AutodiscoveredServlet.java b/micro-boot/src/test/java/app/servlet/com/aol/micro/server/AutodiscoveredServlet.java deleted file mode 100644 index 3e64043bf..000000000 --- a/micro-boot/src/test/java/app/servlet/com/aol/micro/server/AutodiscoveredServlet.java +++ /dev/null @@ -1,30 +0,0 @@ -package app.servlet.com.aol.micro.server; - -import java.io.IOException; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.AutoServletConfiguration; - -@Component -public class AutodiscoveredServlet extends HttpServlet implements AutoServletConfiguration { - - @Override - public String[] getMapping() { - return new String[] { "/servlet" }; - } - - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) - throws ServletException, IOException { - - resp.setContentType("text/html"); - resp.getWriter().write("hello world"); - } - -} diff --git a/micro-boot/src/test/java/app/servlet/com/aol/micro/server/ConfiguredServlet.java b/micro-boot/src/test/java/app/servlet/com/aol/micro/server/ConfiguredServlet.java deleted file mode 100644 index 92577a92e..000000000 --- a/micro-boot/src/test/java/app/servlet/com/aol/micro/server/ConfiguredServlet.java +++ /dev/null @@ -1,24 +0,0 @@ -package app.servlet.com.aol.micro.server; - -import java.io.IOException; - -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -public class ConfiguredServlet extends HttpServlet { - - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) - throws ServletException, IOException { - resp.setContentType("text/html"); - resp.getWriter().write("configured servlet"); - } - - - -} diff --git a/micro-boot/src/test/java/app/servlet/com/aol/micro/server/ServletRunnerTest.java b/micro-boot/src/test/java/app/servlet/com/aol/micro/server/ServletRunnerTest.java deleted file mode 100644 index aa6e20b4f..000000000 --- a/micro-boot/src/test/java/app/servlet/com/aol/micro/server/ServletRunnerTest.java +++ /dev/null @@ -1,64 +0,0 @@ -package app.servlet.com.aol.micro.server; - - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.ExecutionException; - -import javax.servlet.Servlet; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.testing.RestAgent; - -public class ServletRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer(){ - Map servlets = new HashMap<>(); - servlets.put("/configured", new ConfiguredServlet()); - server = new MicroserverApp( AppRunnerLocalMain.class, ConfigurableModule.builder().context("test-app").servlets(servlets ).build()); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - assertThat(rest.get("http://localhost:8080/test-app/servlet/ping"),is("ok")); - - } - - @Test - public void autoDiscoveredServletTest() throws InterruptedException, ExecutionException{ - - - assertThat(rest.get("http://localhost:8080/servlet"),is("hello world")); - - } - - @Test - public void configuredServletTest() throws InterruptedException, ExecutionException{ - - - assertThat(rest.get("http://localhost:8080/configured"),is("configured servlet")); - - } - - -} diff --git a/micro-boot/src/test/java/app/servlet/com/aol/micro/server/ServletStatusResource.java b/micro-boot/src/test/java/app/servlet/com/aol/micro/server/ServletStatusResource.java deleted file mode 100644 index 890a64679..000000000 --- a/micro-boot/src/test/java/app/servlet/com/aol/micro/server/ServletStatusResource.java +++ /dev/null @@ -1,22 +0,0 @@ -package app.servlet.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.RestResource; - -@Component -@Path("/servlet") -public class ServletStatusResource implements RestResource { - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "ok"; - } - -} \ No newline at end of file diff --git a/micro-boot/src/test/java/app/servlet/com/oath/micro/server/AppRunnerLocalMain.java b/micro-boot/src/test/java/app/servlet/com/oath/micro/server/AppRunnerLocalMain.java new file mode 100644 index 000000000..217fc92d4 --- /dev/null +++ b/micro-boot/src/test/java/app/servlet/com/oath/micro/server/AppRunnerLocalMain.java @@ -0,0 +1,20 @@ +package app.servlet.com.oath.micro.server; + + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +import com.oath.micro.server.MicroserverApp; + +@Configuration +@ComponentScan(basePackages = { "app.servlet.com.oath.micro.server" }) +public class AppRunnerLocalMain { + + + public static void main(String[] args) throws InterruptedException { + + new MicroserverApp( AppRunnerLocalMain.class, () -> "test-app") + .run(); + } + +} diff --git a/micro-boot/src/test/java/app/servlet/com/oath/micro/server/AutodiscoveredServlet.java b/micro-boot/src/test/java/app/servlet/com/oath/micro/server/AutodiscoveredServlet.java new file mode 100644 index 000000000..66cbfd59c --- /dev/null +++ b/micro-boot/src/test/java/app/servlet/com/oath/micro/server/AutodiscoveredServlet.java @@ -0,0 +1,30 @@ +package app.servlet.com.oath.micro.server; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.AutoServletConfiguration; + +@Component +public class AutodiscoveredServlet extends HttpServlet implements AutoServletConfiguration { + + @Override + public String[] getMapping() { + return new String[] { "/servlet" }; + } + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + + resp.setContentType("text/html"); + resp.getWriter().write("hello world"); + } + +} diff --git a/micro-boot/src/test/java/app/servlet/com/oath/micro/server/ConfiguredServlet.java b/micro-boot/src/test/java/app/servlet/com/oath/micro/server/ConfiguredServlet.java new file mode 100644 index 000000000..65de82291 --- /dev/null +++ b/micro-boot/src/test/java/app/servlet/com/oath/micro/server/ConfiguredServlet.java @@ -0,0 +1,21 @@ +package app.servlet.com.oath.micro.server; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class ConfiguredServlet extends HttpServlet { + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + resp.setContentType("text/html"); + resp.getWriter().write("configured servlet"); + } + + + +} diff --git a/micro-boot/src/test/java/app/servlet/com/oath/micro/server/ServletRunnerTest.java b/micro-boot/src/test/java/app/servlet/com/oath/micro/server/ServletRunnerTest.java new file mode 100644 index 000000000..39f3896e3 --- /dev/null +++ b/micro-boot/src/test/java/app/servlet/com/oath/micro/server/ServletRunnerTest.java @@ -0,0 +1,64 @@ +package app.servlet.com.oath.micro.server; + + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ExecutionException; + +import javax.servlet.Servlet; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.module.ConfigurableModule; +import com.oath.micro.server.testing.RestAgent; + +public class ServletRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer(){ + Map servlets = new HashMap<>(); + servlets.put("/configured", new ConfiguredServlet()); + server = new MicroserverApp( AppRunnerLocalMain.class, ConfigurableModule.builder().context("test-app").servlets(servlets ).build()); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + assertThat(rest.get("http://localhost:8080/test-app/servlet/ping"),is("ok")); + + } + + @Test + public void autoDiscoveredServletTest() throws InterruptedException, ExecutionException{ + + + assertThat(rest.get("http://localhost:8080/servlet"),is("hello world")); + + } + + @Test + public void configuredServletTest() throws InterruptedException, ExecutionException{ + + + assertThat(rest.get("http://localhost:8080/configured"),is("configured servlet")); + + } + + +} diff --git a/micro-boot/src/test/java/app/servlet/com/oath/micro/server/ServletStatusResource.java b/micro-boot/src/test/java/app/servlet/com/oath/micro/server/ServletStatusResource.java new file mode 100644 index 000000000..6d86eeb84 --- /dev/null +++ b/micro-boot/src/test/java/app/servlet/com/oath/micro/server/ServletStatusResource.java @@ -0,0 +1,22 @@ +package app.servlet.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.RestResource; + +@Component +@Path("/servlet") +public class ServletStatusResource implements RestResource { + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "ok"; + } + +} \ No newline at end of file diff --git a/micro-boot/src/test/java/app/simple/com/aol/micro/server/SimpleRunnerTest.java b/micro-boot/src/test/java/app/simple/com/aol/micro/server/SimpleRunnerTest.java deleted file mode 100644 index 77d4f7595..000000000 --- a/micro-boot/src/test/java/app/simple/com/aol/micro/server/SimpleRunnerTest.java +++ /dev/null @@ -1,49 +0,0 @@ -package app.simple.com.aol.micro.server; - - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.boot.config.Microboot; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.testing.RestAgent; - -@Microserver @Microboot -public class SimpleRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer(){ - - server = new MicroserverApp( SimpleRunnerTest.class, ()-> "simple-app"); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - - - assertThat(rest.get("http://localhost:8080/simple-app/status/ping"),is("ok")); - - - } - - - -} diff --git a/micro-boot/src/test/java/app/simple/com/aol/micro/server/SimpleStatusResource.java b/micro-boot/src/test/java/app/simple/com/aol/micro/server/SimpleStatusResource.java deleted file mode 100644 index 0093fe138..000000000 --- a/micro-boot/src/test/java/app/simple/com/aol/micro/server/SimpleStatusResource.java +++ /dev/null @@ -1,28 +0,0 @@ -package app.simple.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.RestResource; - -@Component -@Qualifier("simpleStatusResource") -@Path("/status") -public class SimpleStatusResource implements RestResource { - - - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - - return "ok"; - } - - -} \ No newline at end of file diff --git a/micro-boot/src/test/java/app/simple/com/oath/micro/server/SimpleRunnerTest.java b/micro-boot/src/test/java/app/simple/com/oath/micro/server/SimpleRunnerTest.java new file mode 100644 index 000000000..cf8c92d17 --- /dev/null +++ b/micro-boot/src/test/java/app/simple/com/oath/micro/server/SimpleRunnerTest.java @@ -0,0 +1,49 @@ +package app.simple.com.oath.micro.server; + + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.boot.config.Microboot; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.testing.RestAgent; + +@Microserver @Microboot +public class SimpleRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer(){ + + server = new MicroserverApp( SimpleRunnerTest.class, ()-> "simple-app"); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + + + assertThat(rest.get("http://localhost:8080/simple-app/status/ping"),is("ok")); + + + } + + + +} diff --git a/micro-boot/src/test/java/app/simple/com/oath/micro/server/SimpleStatusResource.java b/micro-boot/src/test/java/app/simple/com/oath/micro/server/SimpleStatusResource.java new file mode 100644 index 000000000..97265ed02 --- /dev/null +++ b/micro-boot/src/test/java/app/simple/com/oath/micro/server/SimpleStatusResource.java @@ -0,0 +1,28 @@ +package app.simple.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.RestResource; + +@Component +@Qualifier("simpleStatusResource") +@Path("/status") +public class SimpleStatusResource implements RestResource { + + + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + + return "ok"; + } + + +} \ No newline at end of file diff --git a/micro-boot/src/test/java/app/single/com/aol/micro/server/SingleClassTest.java b/micro-boot/src/test/java/app/single/com/aol/micro/server/SingleClassTest.java deleted file mode 100644 index cd8720d48..000000000 --- a/micro-boot/src/test/java/app/single/com/aol/micro/server/SingleClassTest.java +++ /dev/null @@ -1,60 +0,0 @@ -package app.single.com.aol.micro.server; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.RestResource; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.testing.RestAgent; - -@Microserver -@Path("/single") -@Ignore -public class SingleClassTest implements RestResource{ - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer(){ - - server = new MicroserverApp( ()-> "simple-app"); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - - - assertThat(rest.get("http://localhost:8080/simple-app/single/ping"),is("ok")); - - } - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "ok"; - } - - -} \ No newline at end of file diff --git a/micro-boot/src/test/java/app/single/com/oath/micro/server/SingleClassTest.java b/micro-boot/src/test/java/app/single/com/oath/micro/server/SingleClassTest.java new file mode 100644 index 000000000..bc1a5a5b1 --- /dev/null +++ b/micro-boot/src/test/java/app/single/com/oath/micro/server/SingleClassTest.java @@ -0,0 +1,60 @@ +package app.single.com.oath.micro.server; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.auto.discovery.RestResource; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.testing.RestAgent; + +@Microserver +@Path("/single") +@Ignore +public class SingleClassTest implements RestResource{ + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer(){ + + server = new MicroserverApp( ()-> "simple-app"); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + + + assertThat(rest.get("http://localhost:8080/simple-app/single/ping"),is("ok")); + + } + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "ok"; + } + + +} \ No newline at end of file diff --git a/micro-boot/src/test/java/app/single/main/com/aol/micro/server/SingleClassApp.java b/micro-boot/src/test/java/app/single/main/com/aol/micro/server/SingleClassApp.java deleted file mode 100644 index 1d544a1cf..000000000 --- a/micro-boot/src/test/java/app/single/main/com/aol/micro/server/SingleClassApp.java +++ /dev/null @@ -1,30 +0,0 @@ -package app.single.main.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.junit.Ignore; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; -import org.springframework.stereotype.Component; - -import com.aol.micro.server.MicroserverApp; - -@Configuration -@ComponentScan(basePackages = { "app.simple.com.aol.micro.server" }) -@Component -@Path("/status") @Ignore -public class SingleClassApp { - - public static void main(String[] args){ - new MicroserverApp( SingleClassApp.class, ()-> "simple-app"); - } - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "ok"; - } - -} diff --git a/micro-boot/src/test/java/app/single/main/com/oath/micro/server/SingleClassApp.java b/micro-boot/src/test/java/app/single/main/com/oath/micro/server/SingleClassApp.java new file mode 100644 index 000000000..04d145ba8 --- /dev/null +++ b/micro-boot/src/test/java/app/single/main/com/oath/micro/server/SingleClassApp.java @@ -0,0 +1,30 @@ +package app.single.main.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.junit.Ignore; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.stereotype.Component; + +import com.oath.micro.server.MicroserverApp; + +@Configuration +@ComponentScan(basePackages = { "app.simple.com.aol.micro.server" }) +@Component +@Path("/status") @Ignore +public class SingleClassApp { + + public static void main(String[] args){ + new MicroserverApp( SingleClassApp.class, ()-> "simple-app"); + } + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "ok"; + } + +} diff --git a/micro-boot/src/test/java/app/spring/com/aol/micro/server/MyBean.java b/micro-boot/src/test/java/app/spring/com/aol/micro/server/MyBean.java deleted file mode 100644 index 1f7a589ff..000000000 --- a/micro-boot/src/test/java/app/spring/com/aol/micro/server/MyBean.java +++ /dev/null @@ -1,12 +0,0 @@ -package app.spring.com.aol.micro.server; - -import javax.inject.Inject; - -import lombok.Getter; - -@Getter -public class MyBean { - - @Inject - private MyDependency injected; -} diff --git a/micro-boot/src/test/java/app/spring/com/aol/micro/server/MyDependency.java b/micro-boot/src/test/java/app/spring/com/aol/micro/server/MyDependency.java deleted file mode 100644 index 48d89e6c5..000000000 --- a/micro-boot/src/test/java/app/spring/com/aol/micro/server/MyDependency.java +++ /dev/null @@ -1,12 +0,0 @@ -package app.spring.com.aol.micro.server; - -import lombok.Getter; - -import org.springframework.stereotype.Component; - -@Component -@Getter -public class MyDependency { - - private String data = "hello world"; -} diff --git a/micro-boot/src/test/java/app/spring/com/aol/micro/server/SpringRunnerTest.java b/micro-boot/src/test/java/app/spring/com/aol/micro/server/SpringRunnerTest.java deleted file mode 100644 index 9bedc885f..000000000 --- a/micro-boot/src/test/java/app/spring/com/aol/micro/server/SpringRunnerTest.java +++ /dev/null @@ -1,55 +0,0 @@ -package app.spring.com.aol.micro.server; - - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.springframework.context.annotation.Bean; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.boot.config.Microboot; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.testing.RestAgent; -/**@Configuration -@ComponentScan(basePackages = { "app.spring.com.aol.micro.server" })**/ -@Microserver @Microboot -public class SpringRunnerTest { - - RestAgent rest = new RestAgent(); - - @Bean - public MyBean mybean(){ - return new MyBean(); - } - - MicroserverApp server; - @Before - public void startServer(){ - - server = new MicroserverApp( SpringRunnerTest.class, ()-> "spring-app"); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void testAutoWiring() throws InterruptedException, ExecutionException{ - - assertThat(rest.get("http://localhost:8080/spring-app/spring/ping"),is("hello world")); - - } - - - - - -} diff --git a/micro-boot/src/test/java/app/spring/com/aol/micro/server/SpringStatusResource.java b/micro-boot/src/test/java/app/spring/com/aol/micro/server/SpringStatusResource.java deleted file mode 100644 index 331ac997e..000000000 --- a/micro-boot/src/test/java/app/spring/com/aol/micro/server/SpringStatusResource.java +++ /dev/null @@ -1,32 +0,0 @@ -package app.spring.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.RestResource; - -@Component -@Path("/spring") -public class SpringStatusResource implements RestResource { - - @Autowired - private MyBean mybean; - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return mybean.getInjected().getData(); - } - @GET - @Produces("text/plain") - @Path("/ping2") - public String ping2() { - return "ok"; - } - -} \ No newline at end of file diff --git a/micro-boot/src/test/java/app/spring/com/oath/micro/server/MyBean.java b/micro-boot/src/test/java/app/spring/com/oath/micro/server/MyBean.java new file mode 100644 index 000000000..328b7d185 --- /dev/null +++ b/micro-boot/src/test/java/app/spring/com/oath/micro/server/MyBean.java @@ -0,0 +1,12 @@ +package app.spring.com.oath.micro.server; + +import javax.inject.Inject; + +import lombok.Getter; + +@Getter +public class MyBean { + + @Inject + private MyDependency injected; +} diff --git a/micro-boot/src/test/java/app/spring/com/oath/micro/server/MyDependency.java b/micro-boot/src/test/java/app/spring/com/oath/micro/server/MyDependency.java new file mode 100644 index 000000000..1ca23b15b --- /dev/null +++ b/micro-boot/src/test/java/app/spring/com/oath/micro/server/MyDependency.java @@ -0,0 +1,12 @@ +package app.spring.com.oath.micro.server; + +import lombok.Getter; + +import org.springframework.stereotype.Component; + +@Component +@Getter +public class MyDependency { + + private String data = "hello world"; +} diff --git a/micro-boot/src/test/java/app/spring/com/oath/micro/server/SpringRunnerTest.java b/micro-boot/src/test/java/app/spring/com/oath/micro/server/SpringRunnerTest.java new file mode 100644 index 000000000..0a799afda --- /dev/null +++ b/micro-boot/src/test/java/app/spring/com/oath/micro/server/SpringRunnerTest.java @@ -0,0 +1,55 @@ +package app.spring.com.oath.micro.server; + + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.springframework.context.annotation.Bean; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.boot.config.Microboot; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.testing.RestAgent; +/**@Configuration +@ComponentScan(basePackages = { "app.spring.com.aol.micro.server" })**/ +@Microserver @Microboot +public class SpringRunnerTest { + + RestAgent rest = new RestAgent(); + + @Bean + public MyBean mybean(){ + return new MyBean(); + } + + MicroserverApp server; + @Before + public void startServer(){ + + server = new MicroserverApp( SpringRunnerTest.class, ()-> "spring-app"); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void testAutoWiring() throws InterruptedException, ExecutionException{ + + assertThat(rest.get("http://localhost:8080/spring-app/spring/ping"),is("hello world")); + + } + + + + + +} diff --git a/micro-boot/src/test/java/app/spring/com/oath/micro/server/SpringStatusResource.java b/micro-boot/src/test/java/app/spring/com/oath/micro/server/SpringStatusResource.java new file mode 100644 index 000000000..ae0c817de --- /dev/null +++ b/micro-boot/src/test/java/app/spring/com/oath/micro/server/SpringStatusResource.java @@ -0,0 +1,32 @@ +package app.spring.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.RestResource; + +@Component +@Path("/spring") +public class SpringStatusResource implements RestResource { + + @Autowired + private MyBean mybean; + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return mybean.getInjected().getData(); + } + @GET + @Produces("text/plain") + @Path("/ping2") + public String ping2() { + return "ok"; + } + +} \ No newline at end of file diff --git a/micro-boot/src/test/java/app/swagger/com/aol/micro/server/StatsResource.java b/micro-boot/src/test/java/app/swagger/com/aol/micro/server/StatsResource.java deleted file mode 100644 index 3d3516a41..000000000 --- a/micro-boot/src/test/java/app/swagger/com/aol/micro/server/StatsResource.java +++ /dev/null @@ -1,31 +0,0 @@ -package app.swagger.com.aol.micro.server; - -import java.util.List; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.RestResource; -import com.google.common.collect.ImmutableList; -import com.wordnik.swagger.annotations.Api; -import com.wordnik.swagger.annotations.ApiOperation; - - -@Path("/stats") -@Component -@Api(value = "/stats", description = "Resource to show stats for a box using sigar") -public class StatsResource implements RestResource { - - - - @GET - @Path("/ping") - @Produces("application/json") - @ApiOperation(value = "Make a ping call", response = List.class) - public List getMachineStats() { - return ImmutableList.of(1); - } -} diff --git a/micro-boot/src/test/java/app/swagger/com/aol/micro/server/SwaggerRunnerTest.java b/micro-boot/src/test/java/app/swagger/com/aol/micro/server/SwaggerRunnerTest.java deleted file mode 100644 index 2f05228b3..000000000 --- a/micro-boot/src/test/java/app/swagger/com/aol/micro/server/SwaggerRunnerTest.java +++ /dev/null @@ -1,49 +0,0 @@ -package app.swagger.com.aol.micro.server; - -import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.testing.RestAgent; - -@Configuration -@ComponentScan(basePackages = { "app.swagger.com.aol.micro.server" }) -public class SwaggerRunnerTest { - - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer(){ - - server = new MicroserverApp( SwaggerRunnerTest.class, ()-> "swagger-app"); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - - - assertThat(rest.getJson("http://localhost:8080/api-docs/stats"),containsString("Make a ping call")); - - } - - - -} diff --git a/micro-boot/src/test/java/app/swagger/com/oath/micro/server/StatsResource.java b/micro-boot/src/test/java/app/swagger/com/oath/micro/server/StatsResource.java new file mode 100644 index 000000000..848d10205 --- /dev/null +++ b/micro-boot/src/test/java/app/swagger/com/oath/micro/server/StatsResource.java @@ -0,0 +1,31 @@ +package app.swagger.com.oath.micro.server; + +import java.util.List; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.RestResource; +import com.google.common.collect.ImmutableList; +import com.wordnik.swagger.annotations.Api; +import com.wordnik.swagger.annotations.ApiOperation; + + +@Path("/stats") +@Component +@Api(value = "/stats", description = "Resource to show stats for a box using sigar") +public class StatsResource implements RestResource { + + + + @GET + @Path("/ping") + @Produces("application/json") + @ApiOperation(value = "Make a ping call", response = List.class) + public List getMachineStats() { + return ImmutableList.of(1); + } +} diff --git a/micro-boot/src/test/java/app/swagger/com/oath/micro/server/SwaggerRunnerTest.java b/micro-boot/src/test/java/app/swagger/com/oath/micro/server/SwaggerRunnerTest.java new file mode 100644 index 000000000..5f9c6351c --- /dev/null +++ b/micro-boot/src/test/java/app/swagger/com/oath/micro/server/SwaggerRunnerTest.java @@ -0,0 +1,49 @@ +package app.swagger.com.oath.micro.server; + +import static org.hamcrest.Matchers.containsString; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.testing.RestAgent; + +@Configuration +@ComponentScan(basePackages = { "app.swagger.com.oath.micro.server" }) +public class SwaggerRunnerTest { + + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer(){ + + server = new MicroserverApp( SwaggerRunnerTest.class, ()-> "swagger-app"); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + + + assertThat(rest.getJson("http://localhost:8080/api-docs/stats"),containsString("Make a ping call")); + + } + + + +} diff --git a/micro-boot/src/test/java/com/aol/micro/server/testing/RestAgent.java b/micro-boot/src/test/java/com/aol/micro/server/testing/RestAgent.java deleted file mode 100644 index ce204f810..000000000 --- a/micro-boot/src/test/java/com/aol/micro/server/testing/RestAgent.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.aol.micro.server.testing; - -import java.util.List; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.Invocation.Builder; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; - -import com.aol.micro.server.rest.jackson.JacksonUtil; - -public class RestAgent { - - - public String getJson(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.get(String.class); - - } - - public String get(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.TEXT_PLAIN); - - return request.get(String.class); - - } - - public T post(String url, Object payload,Class type) { - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); - } - - -} diff --git a/micro-boot/src/test/java/com/oath/micro/server/testing/RestAgent.java b/micro-boot/src/test/java/com/oath/micro/server/testing/RestAgent.java new file mode 100644 index 000000000..b2b86303e --- /dev/null +++ b/micro-boot/src/test/java/com/oath/micro/server/testing/RestAgent.java @@ -0,0 +1,53 @@ +package com.oath.micro.server.testing; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.Invocation.Builder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; + +import com.oath.micro.server.rest.jackson.JacksonUtil; + +public class RestAgent { + + + public String getJson(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.get(String.class); + + } + + public String get(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.TEXT_PLAIN); + + return request.get(String.class); + + } + + public T post(String url, Object payload,Class type) { + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); + } + + +} diff --git a/micro-boot/src/test/java/nonautoscan/com/aol/micro/server/ConfiguredListener.java b/micro-boot/src/test/java/nonautoscan/com/aol/micro/server/ConfiguredListener.java deleted file mode 100644 index d15010390..000000000 --- a/micro-boot/src/test/java/nonautoscan/com/aol/micro/server/ConfiguredListener.java +++ /dev/null @@ -1,25 +0,0 @@ -package nonautoscan.com.aol.micro.server; - -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; - -import lombok.Getter; - -public class ConfiguredListener implements ServletContextListener { - - @Getter - private static volatile int called= 0; - - @Override - public void contextInitialized(ServletContextEvent sce) { - called ++; - - } - - @Override - public void contextDestroyed(ServletContextEvent sce) { - - - } - -} \ No newline at end of file diff --git a/micro-boot/src/test/java/nonautoscan/com/aol/micro/server/PropertyFileConfigTest.java b/micro-boot/src/test/java/nonautoscan/com/aol/micro/server/PropertyFileConfigTest.java deleted file mode 100644 index 71f038db3..000000000 --- a/micro-boot/src/test/java/nonautoscan/com/aol/micro/server/PropertyFileConfigTest.java +++ /dev/null @@ -1,32 +0,0 @@ -package nonautoscan.com.aol.micro.server; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.junit.Assert.assertThat; - -import java.io.IOException; - -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.config.Config; -import com.aol.micro.server.spring.properties.PropertyFileConfig; -public class PropertyFileConfigTest { - - - - - - PropertyFileConfig config; - @Before - public void setUp() { - config = new PropertyFileConfig(); - } - - @Test - public void testPropertyPlaceholderConfigurer() throws IOException { - Config.instance(); - assertThat( config.propertyPlaceholderConfigurer(),notNullValue()); - } - - - -} diff --git a/micro-boot/src/test/java/nonautoscan/com/aol/micro/server/ScheduleAndAsyncConfigTest.groovy b/micro-boot/src/test/java/nonautoscan/com/aol/micro/server/ScheduleAndAsyncConfigTest.groovy deleted file mode 100644 index 071c36e08..000000000 --- a/micro-boot/src/test/java/nonautoscan/com/aol/micro/server/ScheduleAndAsyncConfigTest.groovy +++ /dev/null @@ -1,56 +0,0 @@ -package nonautoscan.com.aol.micro.server - -import static org.junit.Assert.* -import groovy.transform.CompileStatic - -import org.junit.Before -import org.junit.Test -import org.mockito.Mockito -import org.springframework.scheduling.config.ScheduledTaskRegistrar -@CompileStatic -class ScheduleAndAsyncConfigTest { - - - ScheduleAndAsyncConfig config - @Before - public void setup(){ - config = new ScheduleAndAsyncConfig() - config.schedulerThreadPoolSize=3 - config.executorThreadPoolSize=3 - } - @Test - public void testSetExecutorThreadPoolSize() { - assert config.@executorThreadPoolSize==3 - } - - @Test - public void testSetSchedulerThreadPoolSize() { - - assert config.@schedulerThreadPoolSize==3 - } - - @Test - public void testGetAsyncExecutor() { - assert config.asyncExecutor !=null - } - - @Test - public void testConfigureTasks() { - ScheduledTaskRegistrar mock = Mockito.mock(ScheduledTaskRegistrar) - config.configureTasks(mock) - Mockito.verify(mock).setScheduler(Mockito.anyObject()) - } - - @Test - public void testTaskScheduler() { - assert config.taskScheduler()!=null - } - - @Test - public void testTaskExecutor() { - assert config.taskExecutor() != null - } - - - -} \ No newline at end of file diff --git a/micro-boot/src/test/java/nonautoscan/com/oath/micro/server/ConfiguredListener.java b/micro-boot/src/test/java/nonautoscan/com/oath/micro/server/ConfiguredListener.java new file mode 100644 index 000000000..cc1161808 --- /dev/null +++ b/micro-boot/src/test/java/nonautoscan/com/oath/micro/server/ConfiguredListener.java @@ -0,0 +1,25 @@ +package nonautoscan.com.oath.micro.server; + +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; + +import lombok.Getter; + +public class ConfiguredListener implements ServletContextListener { + + @Getter + private static volatile int called= 0; + + @Override + public void contextInitialized(ServletContextEvent sce) { + called ++; + + } + + @Override + public void contextDestroyed(ServletContextEvent sce) { + + + } + +} \ No newline at end of file diff --git a/micro-boot/src/test/java/nonautoscan/com/oath/micro/server/PropertyFileConfigTest.java b/micro-boot/src/test/java/nonautoscan/com/oath/micro/server/PropertyFileConfigTest.java new file mode 100644 index 000000000..7f341009e --- /dev/null +++ b/micro-boot/src/test/java/nonautoscan/com/oath/micro/server/PropertyFileConfigTest.java @@ -0,0 +1,32 @@ +package nonautoscan.com.oath.micro.server; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.junit.Assert.assertThat; + +import java.io.IOException; + +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.config.Config; +import com.oath.micro.server.spring.properties.PropertyFileConfig; +public class PropertyFileConfigTest { + + + + + + PropertyFileConfig config; + @Before + public void setUp() { + config = new PropertyFileConfig(); + } + + @Test + public void testPropertyPlaceholderConfigurer() throws IOException { + Config.instance(); + assertThat( config.propertyPlaceholderConfigurer(),notNullValue()); + } + + + +} diff --git a/micro-boot/src/test/java/nonautoscan/com/oath/micro/server/ScheduleAndAsyncConfigTest.groovy b/micro-boot/src/test/java/nonautoscan/com/oath/micro/server/ScheduleAndAsyncConfigTest.groovy new file mode 100644 index 000000000..3090aa418 --- /dev/null +++ b/micro-boot/src/test/java/nonautoscan/com/oath/micro/server/ScheduleAndAsyncConfigTest.groovy @@ -0,0 +1,55 @@ +package nonautoscan.com.oath.micro.server + +import groovy.transform.CompileStatic + +import org.junit.Before +import org.junit.Test +import org.mockito.Mockito +import org.springframework.scheduling.config.ScheduledTaskRegistrar +@CompileStatic +class ScheduleAndAsyncConfigTest { + + + ScheduleAndAsyncConfig config + @Before + public void setup(){ + config = new ScheduleAndAsyncConfig() + config.schedulerThreadPoolSize=3 + config.executorThreadPoolSize=3 + } + @Test + public void testSetExecutorThreadPoolSize() { + assert config.@executorThreadPoolSize==3 + } + + @Test + public void testSetSchedulerThreadPoolSize() { + + assert config.@schedulerThreadPoolSize==3 + } + + @Test + public void testGetAsyncExecutor() { + assert config.asyncExecutor !=null + } + + @Test + public void testConfigureTasks() { + ScheduledTaskRegistrar mock = Mockito.mock(ScheduledTaskRegistrar) + config.configureTasks(mock) + Mockito.verify(mock).setScheduler(Mockito.anyObject()) + } + + @Test + public void testTaskScheduler() { + assert config.taskScheduler()!=null + } + + @Test + public void testTaskExecutor() { + assert config.taskExecutor() != null + } + + + +} \ No newline at end of file diff --git a/micro-client/src/main/java/com/aol/micro/server/rest/client/nio/ClientPlugin.java b/micro-client/src/main/java/com/aol/micro/server/rest/client/nio/ClientPlugin.java deleted file mode 100644 index 7e287c958..000000000 --- a/micro-client/src/main/java/com/aol/micro/server/rest/client/nio/ClientPlugin.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.aol.micro.server.rest.client.nio; - - -import com.aol.micro.server.Plugin; -import cyclops.collections.immutable.PersistentSetX; -import cyclops.collections.mutable.SetX; - -import java.util.Set; - -/** - * - * @author johnmcclean - * - */ -public class ClientPlugin implements Plugin{ - - @Override - public Set springClasses() { - return SetX.of(SpringConfig.class); - } - - - -} diff --git a/micro-client/src/main/java/com/aol/micro/server/rest/client/RestClient.java b/micro-client/src/main/java/com/oath/micro/server/rest/client/RestClient.java similarity index 96% rename from micro-client/src/main/java/com/aol/micro/server/rest/client/RestClient.java rename to micro-client/src/main/java/com/oath/micro/server/rest/client/RestClient.java index 6cb17ccb6..922f24a22 100644 --- a/micro-client/src/main/java/com/aol/micro/server/rest/client/RestClient.java +++ b/micro-client/src/main/java/com/oath/micro/server/rest/client/RestClient.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.rest.client; +package com.oath.micro.server.rest.client; import java.util.concurrent.CompletableFuture; @@ -16,8 +16,8 @@ import org.glassfish.jersey.client.ClientProperties; -import com.aol.micro.server.rest.jackson.JacksonFeature; -import com.aol.micro.server.rest.jackson.JacksonUtil; +import com.oath.micro.server.rest.jackson.JacksonFeature; +import com.oath.micro.server.rest.jackson.JacksonUtil; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider; diff --git a/micro-client/src/main/java/com/aol/micro/server/rest/client/nio/AsyncRestClient.java b/micro-client/src/main/java/com/oath/micro/server/rest/client/nio/AsyncRestClient.java similarity index 97% rename from micro-client/src/main/java/com/aol/micro/server/rest/client/nio/AsyncRestClient.java rename to micro-client/src/main/java/com/oath/micro/server/rest/client/nio/AsyncRestClient.java index 75d1f286b..758fb8b4a 100644 --- a/micro-client/src/main/java/com/aol/micro/server/rest/client/nio/AsyncRestClient.java +++ b/micro-client/src/main/java/com/oath/micro/server/rest/client/nio/AsyncRestClient.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.rest.client.nio; +package com.oath.micro.server.rest.client.nio; import java.util.concurrent.CompletableFuture; @@ -16,8 +16,8 @@ import org.glassfish.jersey.client.ClientConfig; import org.glassfish.jersey.client.ClientProperties; -import com.aol.micro.server.rest.jackson.JacksonFeature; -import com.aol.micro.server.rest.jackson.JacksonUtil; +import com.oath.micro.server.rest.jackson.JacksonFeature; +import com.oath.micro.server.rest.jackson.JacksonUtil; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider; diff --git a/micro-client/src/main/java/com/oath/micro/server/rest/client/nio/ClientPlugin.java b/micro-client/src/main/java/com/oath/micro/server/rest/client/nio/ClientPlugin.java new file mode 100644 index 000000000..d719dd267 --- /dev/null +++ b/micro-client/src/main/java/com/oath/micro/server/rest/client/nio/ClientPlugin.java @@ -0,0 +1,23 @@ +package com.oath.micro.server.rest.client.nio; + + +import com.oath.micro.server.Plugin; +import cyclops.collections.mutable.SetX; + +import java.util.Set; + +/** + * + * @author johnmcclean + * + */ +public class ClientPlugin implements Plugin{ + + @Override + public Set springClasses() { + return SetX.of(SpringConfig.class); + } + + + +} diff --git a/micro-client/src/main/java/com/aol/micro/server/rest/client/nio/NIORestClient.java b/micro-client/src/main/java/com/oath/micro/server/rest/client/nio/NIORestClient.java similarity index 98% rename from micro-client/src/main/java/com/aol/micro/server/rest/client/nio/NIORestClient.java rename to micro-client/src/main/java/com/oath/micro/server/rest/client/nio/NIORestClient.java index e154152f6..ed959e16e 100644 --- a/micro-client/src/main/java/com/aol/micro/server/rest/client/nio/NIORestClient.java +++ b/micro-client/src/main/java/com/oath/micro/server/rest/client/nio/NIORestClient.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.rest.client.nio; +package com.oath.micro.server.rest.client.nio; import java.net.URI; @@ -21,7 +21,7 @@ import org.springframework.web.client.ResponseExtractor; import org.springframework.web.client.RestClientException; -import com.aol.micro.server.rest.jackson.JacksonUtil; +import com.oath.micro.server.rest.jackson.JacksonUtil; public class NIORestClient { diff --git a/micro-client/src/main/java/com/aol/micro/server/rest/client/nio/SpringConfig.java b/micro-client/src/main/java/com/oath/micro/server/rest/client/nio/SpringConfig.java similarity index 95% rename from micro-client/src/main/java/com/aol/micro/server/rest/client/nio/SpringConfig.java rename to micro-client/src/main/java/com/oath/micro/server/rest/client/nio/SpringConfig.java index 70d55e197..b4e00906c 100644 --- a/micro-client/src/main/java/com/aol/micro/server/rest/client/nio/SpringConfig.java +++ b/micro-client/src/main/java/com/oath/micro/server/rest/client/nio/SpringConfig.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.rest.client.nio; +package com.oath.micro.server.rest.client.nio; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; diff --git a/micro-client/src/main/resources/META-INF/services/com.aol.micro.server.Plugin b/micro-client/src/main/resources/META-INF/services/com.aol.micro.server.Plugin deleted file mode 100644 index e9ab7dfa3..000000000 --- a/micro-client/src/main/resources/META-INF/services/com.aol.micro.server.Plugin +++ /dev/null @@ -1 +0,0 @@ -com.aol.micro.server.rest.client.nio.ClientPlugin \ No newline at end of file diff --git a/micro-client/src/main/resources/META-INF/services/com.oath.micro.server.Plugin b/micro-client/src/main/resources/META-INF/services/com.oath.micro.server.Plugin new file mode 100644 index 000000000..354098bb6 --- /dev/null +++ b/micro-client/src/main/resources/META-INF/services/com.oath.micro.server.Plugin @@ -0,0 +1 @@ +com.oath.micro.server.rest.client.nio.ClientPlugin \ No newline at end of file diff --git a/micro-client/src/test/java/app/async/com/aol/micro/server/AsyncAppRunner.java b/micro-client/src/test/java/app/async/com/aol/micro/server/AsyncAppRunner.java deleted file mode 100644 index 979b5fbf5..000000000 --- a/micro-client/src/test/java/app/async/com/aol/micro/server/AsyncAppRunner.java +++ /dev/null @@ -1,57 +0,0 @@ -package app.async.com.aol.micro.server; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.io.IOException; -import java.util.Properties; -import java.util.concurrent.ExecutionException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.spring.properties.PropertyFileConfig; -import com.aol.micro.server.testing.RestAgent; - -@Microserver -public class AsyncAppRunner { - - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer(){ - - server = new MicroserverApp( ()-> "async-app"); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - Thread.sleep(2000); - - assertThat(rest.get("http://localhost:8080/async-app/async/expensive"),is(";test!;test!;test!")); - - } - - @Test - public void loadProperties() throws IOException{ - - Properties props = new PropertyFileConfig(true).propertyFactory() ; - assertThat(props.getProperty("test"),is("hello world")); - } - - - -} \ No newline at end of file diff --git a/micro-client/src/test/java/app/async/com/aol/micro/server/AsyncResource.java b/micro-client/src/test/java/app/async/com/aol/micro/server/AsyncResource.java deleted file mode 100644 index 50a0ac78a..000000000 --- a/micro-client/src/test/java/app/async/com/aol/micro/server/AsyncResource.java +++ /dev/null @@ -1,58 +0,0 @@ -package app.async.com.aol.micro.server; - -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.CompletableFuture; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.container.AsyncResponse; -import javax.ws.rs.container.Suspended; - -import cyclops.async.LazyReact; -import org.springframework.stereotype.Component; - - -import com.aol.micro.server.auto.discovery.RestResource; -import com.aol.micro.server.rest.client.nio.AsyncRestClient; - -@Path("/async") -@Component -public class AsyncResource implements RestResource{ - - - private final List urls =Arrays.asList("http://localhost:8080/async-app/async/ping2", - "http://localhost:8080/async-app/async/ping", - "http://localhost:8080/async-app/async/ping", - "http://localhost:8080/async-app/async/ping"); - - private final AsyncRestClient client = new AsyncRestClient(100,100).withAccept("text/plain"); - - @GET - @Path("/expensive") - @Produces("text/plain") - public void expensive(@Suspended AsyncResponse asyncResponse){ - - new LazyReact().fromStreamFutures(urls.stream() - .>map(it -> client.get(it))) - .onFail(it -> "") - .peek(it -> - System.out.println(it)) - .convertToSimpleReact() - .allOf(data -> { - System.out.println(data); - return asyncResponse.resume(String.join(";", (List)data)); }) - .convertToLazyStream().run(); - - } - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "test!"; - } - - -} diff --git a/micro-client/src/test/java/app/async/com/aol/micro/server/Simple.java b/micro-client/src/test/java/app/async/com/aol/micro/server/Simple.java deleted file mode 100644 index edefa80ef..000000000 --- a/micro-client/src/test/java/app/async/com/aol/micro/server/Simple.java +++ /dev/null @@ -1,16 +0,0 @@ -package app.async.com.aol.micro.server; - -import java.io.IOException; -import java.util.Properties; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Config; -import com.aol.micro.server.spring.properties.PropertyFileConfig; - -public class Simple { - - public static void main(String[] args) throws IOException{ - - new MicroserverApp(()->"test-app").run(); - } -} diff --git a/micro-client/src/test/java/app/async/com/aol/micro/server/SimpleApp.java b/micro-client/src/test/java/app/async/com/aol/micro/server/SimpleApp.java deleted file mode 100644 index 919b7c6b0..000000000 --- a/micro-client/src/test/java/app/async/com/aol/micro/server/SimpleApp.java +++ /dev/null @@ -1,24 +0,0 @@ -package app.async.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.Rest; - - - -@Rest -@Path("/test") -public class SimpleApp { - - public static void main(String[] args){ - new MicroserverApp(()->"test-app").run(); - } - @GET - public String myEndPoint(){ - return "hello world!"; - } - - -} diff --git a/micro-client/src/test/java/app/async/com/oath/micro/server/AsyncAppRunner.java b/micro-client/src/test/java/app/async/com/oath/micro/server/AsyncAppRunner.java new file mode 100644 index 000000000..c71dd8184 --- /dev/null +++ b/micro-client/src/test/java/app/async/com/oath/micro/server/AsyncAppRunner.java @@ -0,0 +1,57 @@ +package app.async.com.oath.micro.server; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.io.IOException; +import java.util.Properties; +import java.util.concurrent.ExecutionException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.spring.properties.PropertyFileConfig; +import com.oath.micro.server.testing.RestAgent; + +@Microserver +public class AsyncAppRunner { + + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer(){ + + server = new MicroserverApp( ()-> "async-app"); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + Thread.sleep(2000); + + assertThat(rest.get("http://localhost:8080/async-app/async/expensive"),is(";test!;test!;test!")); + + } + + @Test + public void loadProperties() throws IOException{ + + Properties props = new PropertyFileConfig(true).propertyFactory() ; + assertThat(props.getProperty("test"),is("hello world")); + } + + + +} \ No newline at end of file diff --git a/micro-client/src/test/java/app/async/com/oath/micro/server/AsyncResource.java b/micro-client/src/test/java/app/async/com/oath/micro/server/AsyncResource.java new file mode 100644 index 000000000..31dc15fde --- /dev/null +++ b/micro-client/src/test/java/app/async/com/oath/micro/server/AsyncResource.java @@ -0,0 +1,58 @@ +package app.async.com.oath.micro.server; + +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.CompletableFuture; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.container.AsyncResponse; +import javax.ws.rs.container.Suspended; + +import cyclops.async.LazyReact; +import org.springframework.stereotype.Component; + + +import com.oath.micro.server.auto.discovery.RestResource; +import com.oath.micro.server.rest.client.nio.AsyncRestClient; + +@Path("/async") +@Component +public class AsyncResource implements RestResource{ + + + private final List urls =Arrays.asList("http://localhost:8080/async-app/async/ping2", + "http://localhost:8080/async-app/async/ping", + "http://localhost:8080/async-app/async/ping", + "http://localhost:8080/async-app/async/ping"); + + private final AsyncRestClient client = new AsyncRestClient(100,100).withAccept("text/plain"); + + @GET + @Path("/expensive") + @Produces("text/plain") + public void expensive(@Suspended AsyncResponse asyncResponse){ + + new LazyReact().fromStreamFutures(urls.stream() + .>map(it -> client.get(it))) + .onFail(it -> "") + .peek(it -> + System.out.println(it)) + .convertToSimpleReact() + .allOf(data -> { + System.out.println(data); + return asyncResponse.resume(String.join(";", (List)data)); }) + .convertToLazyStream().run(); + + } + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "test!"; + } + + +} diff --git a/micro-client/src/test/java/app/async/com/oath/micro/server/Simple.java b/micro-client/src/test/java/app/async/com/oath/micro/server/Simple.java new file mode 100644 index 000000000..3eb3e7504 --- /dev/null +++ b/micro-client/src/test/java/app/async/com/oath/micro/server/Simple.java @@ -0,0 +1,13 @@ +package app.async.com.oath.micro.server; + +import java.io.IOException; + +import com.oath.micro.server.MicroserverApp; + +public class Simple { + + public static void main(String[] args) throws IOException{ + + new MicroserverApp(()->"test-app").run(); + } +} diff --git a/micro-client/src/test/java/app/async/com/oath/micro/server/SimpleApp.java b/micro-client/src/test/java/app/async/com/oath/micro/server/SimpleApp.java new file mode 100644 index 000000000..916d0330e --- /dev/null +++ b/micro-client/src/test/java/app/async/com/oath/micro/server/SimpleApp.java @@ -0,0 +1,24 @@ +package app.async.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.auto.discovery.Rest; + + + +@Rest +@Path("/test") +public class SimpleApp { + + public static void main(String[] args){ + new MicroserverApp(()->"test-app").run(); + } + @GET + public String myEndPoint(){ + return "hello world!"; + } + + +} diff --git a/micro-client/src/test/java/app/embedded/com/aol/micro/server/AltAppResource.java b/micro-client/src/test/java/app/embedded/com/aol/micro/server/AltAppResource.java deleted file mode 100644 index d4b8eff5c..000000000 --- a/micro-client/src/test/java/app/embedded/com/aol/micro/server/AltAppResource.java +++ /dev/null @@ -1,23 +0,0 @@ -package app.embedded.com.aol.micro.server; - -import java.util.ArrayList; -import java.util.List; - -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.stereotype.Component; - -@Component -@Path("/alt-status") -public class AltAppResource implements AltAppRestResource { - - @POST - @Produces("application/json") - @Path("/ping") - public List ping(ImmutableEntity entity) { - return entity.getList(); - } - -} diff --git a/micro-client/src/test/java/app/embedded/com/aol/micro/server/AltAppRestResource.java b/micro-client/src/test/java/app/embedded/com/aol/micro/server/AltAppRestResource.java deleted file mode 100644 index 8cb2643e3..000000000 --- a/micro-client/src/test/java/app/embedded/com/aol/micro/server/AltAppRestResource.java +++ /dev/null @@ -1,7 +0,0 @@ -package app.embedded.com.aol.micro.server; - -import com.aol.micro.server.auto.discovery.RestResource; - -public interface AltAppRestResource extends RestResource { - -} diff --git a/micro-client/src/test/java/app/embedded/com/aol/micro/server/EmbeddedAppLocalMain.java b/micro-client/src/test/java/app/embedded/com/aol/micro/server/EmbeddedAppLocalMain.java deleted file mode 100644 index 1c78d4229..000000000 --- a/micro-client/src/test/java/app/embedded/com/aol/micro/server/EmbeddedAppLocalMain.java +++ /dev/null @@ -1,24 +0,0 @@ -package app.embedded.com.aol.micro.server; - - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.module.EmbeddedModule; -import cyclops.collections.immutable.LinkedListX; - -@Microserver(basePackages = { "app.embedded.com.aol.micro.server" }) -public class EmbeddedAppLocalMain { - - - public static void main(String[] args) throws InterruptedException { - - new MicroserverApp( - EmbeddedModule.tagInterfaceModule(LinkedListX.of(TestAppRestResource.class),"test-app"), - EmbeddedModule.tagInterfaceModule(LinkedListX.of(AltAppRestResource.class),"alternative-app")).start(); - - - - } - - -} diff --git a/micro-client/src/test/java/app/embedded/com/aol/micro/server/EmbeddedAppTest.java b/micro-client/src/test/java/app/embedded/com/aol/micro/server/EmbeddedAppTest.java deleted file mode 100644 index 174376f9d..000000000 --- a/micro-client/src/test/java/app/embedded/com/aol/micro/server/EmbeddedAppTest.java +++ /dev/null @@ -1,104 +0,0 @@ -package app.embedded.com.aol.micro.server; - -import static org.hamcrest.Matchers.hasItem; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - -import java.util.List; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; - -import javax.ws.rs.NotFoundException; - -import cyclops.collections.immutable.LinkedListX; -import jersey.repackaged.com.google.common.collect.ImmutableList; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.springframework.util.concurrent.ListenableFuture; -import org.springframework.util.concurrent.ListenableFutureCallback; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.module.EmbeddedModule; -import com.aol.micro.server.testing.RestAgent; - -public class EmbeddedAppTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - - @Before - public void startServer(){ - server = new MicroserverApp(EmbeddedAppLocalMain.class, - EmbeddedModule.tagInterfaceModule(LinkedListX.of(TestAppRestResource.class),"test-app"), - EmbeddedModule.tagInterfaceModule(LinkedListX.of(AltAppRestResource.class),"alternative-app")); - server.start(); - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void confirmExpectedUrlsPresentTest() throws InterruptedException, ExecutionException{ - - assertThat(rest.get("http://localhost:8080/test-app/test-status/ping"),is("test!")); - - - assertThat((List)rest.post("http://localhost:8081/alternative-app/alt-status/ping",new ImmutableEntity("value",ImmutableList.of("hello","world")),List.class), - hasItem("hello")); - - } - - - @Test - public void nonBlockingRestClientTest(){ - assertThat(rest.get("http://localhost:8080/test-app/test-status/rest-calls"),is("-*test!-*test!")); - } - - CompletableFuture toCompletableFuture( - final ListenableFuture listenableFuture - ) { - //create an instance of CompletableFuture - CompletableFuture completable = new CompletableFuture() { - @Override - public boolean cancel(boolean mayInterruptIfRunning) { - // propagate cancel to the listenable future - boolean result = listenableFuture.cancel(mayInterruptIfRunning); - super.cancel(mayInterruptIfRunning); - return result; - } - }; - - // add callback - listenableFuture.addCallback(new ListenableFutureCallback() { - @Override - public void onSuccess(T result) { - completable.complete(result); - } - - @Override - public void onFailure(Throwable t) { - completable.completeExceptionally(t); - } - }); - return completable; - } - - @Test(expected=NotFoundException.class) - public void confirmAltAppCantUseTestAppResources(){ - - assertThat(rest.get("http://localhost:8080/alternative-app/test-status/ping"),is("test!")); - - } - @Test(expected=NotFoundException.class) - public void confirmTestAppCantUseAltAppResources(){ - - assertThat((List)rest.post("http://localhost:8081/test-app/alt-status/ping",new ImmutableEntity("value",ImmutableList.of("hello","world")),List.class), - hasItem("hello")); - - } -} diff --git a/micro-client/src/test/java/app/embedded/com/aol/micro/server/ImmutableEntity.java b/micro-client/src/test/java/app/embedded/com/aol/micro/server/ImmutableEntity.java deleted file mode 100644 index cd593f123..000000000 --- a/micro-client/src/test/java/app/embedded/com/aol/micro/server/ImmutableEntity.java +++ /dev/null @@ -1,29 +0,0 @@ -package app.embedded.com.aol.micro.server; - -import java.util.List; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Builder; - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "") -@XmlRootElement(name = "immutable") -@Getter -@AllArgsConstructor -@Builder -public class ImmutableEntity { - - private final String value; - private final List list; - - public ImmutableEntity() { - this(null,null); - } - -} diff --git a/micro-client/src/test/java/app/embedded/com/aol/micro/server/TestAppResource.java b/micro-client/src/test/java/app/embedded/com/aol/micro/server/TestAppResource.java deleted file mode 100644 index dd2e32f17..000000000 --- a/micro-client/src/test/java/app/embedded/com/aol/micro/server/TestAppResource.java +++ /dev/null @@ -1,55 +0,0 @@ -package app.embedded.com.aol.micro.server; - -import java.util.Arrays; -import java.util.List; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import cyclops.async.SimpleReact; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - - -import com.aol.micro.server.rest.client.nio.NIORestClient; -@Component -@Path("/test-status") -public class TestAppResource implements TestAppRestResource { - - private final SimpleReact simpleReact = new SimpleReact(); - private final NIORestClient template; - private final List urls = Arrays.asList("http://localhost:8081/alternative-app/alt-status/ping", - "http://localhost:8080/test-app/test-status/ping", - "http://localhost:8082/simple-app/status/ping", - "http://localhost:8080/test-app/test-status/ping"); - - @Autowired - public TestAppResource(NIORestClient template) { - - this.template = template; - } - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "test!"; - } - - @GET - @Produces("text/plain") - @Path("/rest-calls") - public String restCallResult(){ - - return simpleReact - .fromStream(urls.stream() - .map(it -> template.getForEntity(it,String.class))) - .then(it -> it.getBody()) - .then(it -> "*"+it) - .peek(loadedAndModified -> System.out.println(loadedAndModified)) - .block().stream().reduce("", (acc,next) -> acc+"-"+next); - - } - -} diff --git a/micro-client/src/test/java/app/embedded/com/aol/micro/server/TestAppRestResource.java b/micro-client/src/test/java/app/embedded/com/aol/micro/server/TestAppRestResource.java deleted file mode 100644 index 3133fd8cc..000000000 --- a/micro-client/src/test/java/app/embedded/com/aol/micro/server/TestAppRestResource.java +++ /dev/null @@ -1,7 +0,0 @@ -package app.embedded.com.aol.micro.server; - -import com.aol.micro.server.auto.discovery.RestResource; - -public interface TestAppRestResource extends RestResource { - -} diff --git a/micro-client/src/test/java/app/embedded/com/oath/micro/server/AltAppResource.java b/micro-client/src/test/java/app/embedded/com/oath/micro/server/AltAppResource.java new file mode 100644 index 000000000..1835ababe --- /dev/null +++ b/micro-client/src/test/java/app/embedded/com/oath/micro/server/AltAppResource.java @@ -0,0 +1,22 @@ +package app.embedded.com.oath.micro.server; + +import java.util.List; + +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.stereotype.Component; + +@Component +@Path("/alt-status") +public class AltAppResource implements AltAppRestResource { + + @POST + @Produces("application/json") + @Path("/ping") + public List ping(ImmutableEntity entity) { + return entity.getList(); + } + +} diff --git a/micro-client/src/test/java/app/embedded/com/oath/micro/server/AltAppRestResource.java b/micro-client/src/test/java/app/embedded/com/oath/micro/server/AltAppRestResource.java new file mode 100644 index 000000000..7045a4f35 --- /dev/null +++ b/micro-client/src/test/java/app/embedded/com/oath/micro/server/AltAppRestResource.java @@ -0,0 +1,7 @@ +package app.embedded.com.oath.micro.server; + +import com.oath.micro.server.auto.discovery.RestResource; + +public interface AltAppRestResource extends RestResource { + +} diff --git a/micro-client/src/test/java/app/embedded/com/oath/micro/server/EmbeddedAppLocalMain.java b/micro-client/src/test/java/app/embedded/com/oath/micro/server/EmbeddedAppLocalMain.java new file mode 100644 index 000000000..d4a4f52bf --- /dev/null +++ b/micro-client/src/test/java/app/embedded/com/oath/micro/server/EmbeddedAppLocalMain.java @@ -0,0 +1,24 @@ +package app.embedded.com.oath.micro.server; + + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.module.EmbeddedModule; +import cyclops.collections.immutable.LinkedListX; + +@Microserver(basePackages = { "app.embedded.com.oath.micro.server" }) +public class EmbeddedAppLocalMain { + + + public static void main(String[] args) throws InterruptedException { + + new MicroserverApp( + EmbeddedModule.tagInterfaceModule(LinkedListX.of(TestAppRestResource.class),"test-app"), + EmbeddedModule.tagInterfaceModule(LinkedListX.of(AltAppRestResource.class),"alternative-app")).start(); + + + + } + + +} diff --git a/micro-client/src/test/java/app/embedded/com/oath/micro/server/EmbeddedAppTest.java b/micro-client/src/test/java/app/embedded/com/oath/micro/server/EmbeddedAppTest.java new file mode 100644 index 000000000..2d5729855 --- /dev/null +++ b/micro-client/src/test/java/app/embedded/com/oath/micro/server/EmbeddedAppTest.java @@ -0,0 +1,104 @@ +package app.embedded.com.oath.micro.server; + +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; + +import javax.ws.rs.NotFoundException; + +import cyclops.collections.immutable.LinkedListX; +import jersey.repackaged.com.google.common.collect.ImmutableList; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.springframework.util.concurrent.ListenableFuture; +import org.springframework.util.concurrent.ListenableFutureCallback; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.module.EmbeddedModule; +import com.oath.micro.server.testing.RestAgent; + +public class EmbeddedAppTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + + @Before + public void startServer(){ + server = new MicroserverApp(EmbeddedAppLocalMain.class, + EmbeddedModule.tagInterfaceModule(LinkedListX.of(TestAppRestResource.class),"test-app"), + EmbeddedModule.tagInterfaceModule(LinkedListX.of(AltAppRestResource.class),"alternative-app")); + server.start(); + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void confirmExpectedUrlsPresentTest() throws InterruptedException, ExecutionException{ + + assertThat(rest.get("http://localhost:8080/test-app/test-status/ping"),is("test!")); + + + assertThat((List)rest.post("http://localhost:8081/alternative-app/alt-status/ping",new ImmutableEntity("value",ImmutableList.of("hello","world")),List.class), + hasItem("hello")); + + } + + + @Test + public void nonBlockingRestClientTest(){ + assertThat(rest.get("http://localhost:8080/test-app/test-status/rest-calls"),is("-*test!-*test!")); + } + + CompletableFuture toCompletableFuture( + final ListenableFuture listenableFuture + ) { + //create an instance of CompletableFuture + CompletableFuture completable = new CompletableFuture() { + @Override + public boolean cancel(boolean mayInterruptIfRunning) { + // propagate cancel to the listenable future + boolean result = listenableFuture.cancel(mayInterruptIfRunning); + super.cancel(mayInterruptIfRunning); + return result; + } + }; + + // add callback + listenableFuture.addCallback(new ListenableFutureCallback() { + @Override + public void onSuccess(T result) { + completable.complete(result); + } + + @Override + public void onFailure(Throwable t) { + completable.completeExceptionally(t); + } + }); + return completable; + } + + @Test(expected=NotFoundException.class) + public void confirmAltAppCantUseTestAppResources(){ + + assertThat(rest.get("http://localhost:8080/alternative-app/test-status/ping"),is("test!")); + + } + @Test(expected=NotFoundException.class) + public void confirmTestAppCantUseAltAppResources(){ + + assertThat((List)rest.post("http://localhost:8081/test-app/alt-status/ping",new ImmutableEntity("value",ImmutableList.of("hello","world")),List.class), + hasItem("hello")); + + } +} diff --git a/micro-client/src/test/java/app/embedded/com/oath/micro/server/ImmutableEntity.java b/micro-client/src/test/java/app/embedded/com/oath/micro/server/ImmutableEntity.java new file mode 100644 index 000000000..337b63b89 --- /dev/null +++ b/micro-client/src/test/java/app/embedded/com/oath/micro/server/ImmutableEntity.java @@ -0,0 +1,29 @@ +package app.embedded.com.oath.micro.server; + +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Builder; + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "") +@XmlRootElement(name = "immutable") +@Getter +@AllArgsConstructor +@Builder +public class ImmutableEntity { + + private final String value; + private final List list; + + public ImmutableEntity() { + this(null,null); + } + +} diff --git a/micro-client/src/test/java/app/embedded/com/oath/micro/server/TestAppResource.java b/micro-client/src/test/java/app/embedded/com/oath/micro/server/TestAppResource.java new file mode 100644 index 000000000..7570c1b89 --- /dev/null +++ b/micro-client/src/test/java/app/embedded/com/oath/micro/server/TestAppResource.java @@ -0,0 +1,55 @@ +package app.embedded.com.oath.micro.server; + +import java.util.Arrays; +import java.util.List; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import cyclops.async.SimpleReact; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + + +import com.oath.micro.server.rest.client.nio.NIORestClient; +@Component +@Path("/test-status") +public class TestAppResource implements TestAppRestResource { + + private final SimpleReact simpleReact = new SimpleReact(); + private final NIORestClient template; + private final List urls = Arrays.asList("http://localhost:8081/alternative-app/alt-status/ping", + "http://localhost:8080/test-app/test-status/ping", + "http://localhost:8082/simple-app/status/ping", + "http://localhost:8080/test-app/test-status/ping"); + + @Autowired + public TestAppResource(NIORestClient template) { + + this.template = template; + } + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "test!"; + } + + @GET + @Produces("text/plain") + @Path("/rest-calls") + public String restCallResult(){ + + return simpleReact + .fromStream(urls.stream() + .map(it -> template.getForEntity(it,String.class))) + .then(it -> it.getBody()) + .then(it -> "*"+it) + .peek(loadedAndModified -> System.out.println(loadedAndModified)) + .block().stream().reduce("", (acc,next) -> acc+"-"+next); + + } + +} diff --git a/micro-client/src/test/java/app/embedded/com/oath/micro/server/TestAppRestResource.java b/micro-client/src/test/java/app/embedded/com/oath/micro/server/TestAppRestResource.java new file mode 100644 index 000000000..7d4df5753 --- /dev/null +++ b/micro-client/src/test/java/app/embedded/com/oath/micro/server/TestAppRestResource.java @@ -0,0 +1,7 @@ +package app.embedded.com.oath.micro.server; + +import com.oath.micro.server.auto.discovery.RestResource; + +public interface TestAppRestResource extends RestResource { + +} diff --git a/micro-client/src/test/java/app/events/com/aol/micro/server/EventRunnerTest.java b/micro-client/src/test/java/app/events/com/aol/micro/server/EventRunnerTest.java deleted file mode 100644 index e19257396..000000000 --- a/micro-client/src/test/java/app/events/com/aol/micro/server/EventRunnerTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package app.events.com.aol.micro.server; - - -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.rest.client.nio.AsyncRestClient; -import com.aol.micro.server.testing.RestAgent; - -@Microserver -public class EventRunnerTest { - - RestAgent rest = new RestAgent(); - private final AsyncRestClient client = new AsyncRestClient(100,100).withAccept("application/json"); - MicroserverApp server; - - - @Before - public void startServer(){ - - server = new MicroserverApp(()-> "event-app"); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - - - assertThat(rest.get("http://localhost:8080/event-app/status/ping"),is("ok")); - - assertThat(client.get("http://localhost:8080/event-app/active/jobs").get(), - containsString("startedAt")); - assertThat(client.get("http://localhost:8080/event-app/active/requests").get(), - containsString("startedAt")); - assertThat(client.get("http://localhost:8080/event-app/manifest").get(), - containsString("Manifest")); - - } - - - -} diff --git a/micro-client/src/test/java/app/events/com/aol/micro/server/EventStatusResource.java b/micro-client/src/test/java/app/events/com/aol/micro/server/EventStatusResource.java deleted file mode 100644 index 7f5bc184b..000000000 --- a/micro-client/src/test/java/app/events/com/aol/micro/server/EventStatusResource.java +++ /dev/null @@ -1,40 +0,0 @@ -package app.events.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.RestResource; -import com.aol.micro.server.events.RequestEvents; -import com.google.common.eventbus.EventBus; - -@Component -@Path("/status") -public class EventStatusResource implements RestResource { - - - - - private final EventBus bus; - - @Autowired - public EventStatusResource(EventBus bus ){ - this.bus = bus; - } - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - bus.post(RequestEvents.start("get", 1l)); - try{ - return "ok"; - }finally{ - bus.post(RequestEvents.finish("get",1l)); - } - } - -} \ No newline at end of file diff --git a/micro-client/src/test/java/app/events/com/aol/micro/server/Job.java b/micro-client/src/test/java/app/events/com/aol/micro/server/Job.java deleted file mode 100644 index 845248592..000000000 --- a/micro-client/src/test/java/app/events/com/aol/micro/server/Job.java +++ /dev/null @@ -1,16 +0,0 @@ -package app.events.com.aol.micro.server; - -import org.springframework.stereotype.Component; - -import com.aol.micro.server.events.ScheduledJob; -import com.aol.micro.server.events.SystemData; - -@Component -public class Job implements ScheduledJob{ - - @Override - public SystemData scheduleAndLog() { - return SystemData.builder().errors(0).processed(2).build(); - } - -} diff --git a/micro-client/src/test/java/app/events/com/aol/micro/server/Schedular.java b/micro-client/src/test/java/app/events/com/aol/micro/server/Schedular.java deleted file mode 100644 index 8b99c6930..000000000 --- a/micro-client/src/test/java/app/events/com/aol/micro/server/Schedular.java +++ /dev/null @@ -1,21 +0,0 @@ -package app.events.com.aol.micro.server; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Component; - -@Component -public class Schedular { - - private final Job job; - - @Autowired - public Schedular(final Job job){ - this.job=job; - } - - @Scheduled(fixedDelay=1) - public synchronized void scheduleTask(){ - job.scheduleAndLog(); - } -} diff --git a/micro-client/src/test/java/app/events/com/oath/micro/server/EventRunnerTest.java b/micro-client/src/test/java/app/events/com/oath/micro/server/EventRunnerTest.java new file mode 100644 index 000000000..eca4fffe6 --- /dev/null +++ b/micro-client/src/test/java/app/events/com/oath/micro/server/EventRunnerTest.java @@ -0,0 +1,58 @@ +package app.events.com.oath.micro.server; + + +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.rest.client.nio.AsyncRestClient; +import com.oath.micro.server.testing.RestAgent; + +@Microserver +public class EventRunnerTest { + + RestAgent rest = new RestAgent(); + private final AsyncRestClient client = new AsyncRestClient(100,100).withAccept("application/json"); + MicroserverApp server; + + + @Before + public void startServer(){ + + server = new MicroserverApp(()-> "event-app"); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + + + assertThat(rest.get("http://localhost:8080/event-app/status/ping"),is("ok")); + + assertThat(client.get("http://localhost:8080/event-app/active/jobs").get(), + containsString("startedAt")); + assertThat(client.get("http://localhost:8080/event-app/active/requests").get(), + containsString("startedAt")); + assertThat(client.get("http://localhost:8080/event-app/manifest").get(), + containsString("Manifest")); + + } + + + +} diff --git a/micro-client/src/test/java/app/events/com/oath/micro/server/EventStatusResource.java b/micro-client/src/test/java/app/events/com/oath/micro/server/EventStatusResource.java new file mode 100644 index 000000000..eade4dc04 --- /dev/null +++ b/micro-client/src/test/java/app/events/com/oath/micro/server/EventStatusResource.java @@ -0,0 +1,40 @@ +package app.events.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.RestResource; +import com.oath.micro.server.events.RequestEvents; +import com.google.common.eventbus.EventBus; + +@Component +@Path("/status") +public class EventStatusResource implements RestResource { + + + + + private final EventBus bus; + + @Autowired + public EventStatusResource(EventBus bus ){ + this.bus = bus; + } + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + bus.post(RequestEvents.start("get", 1l)); + try{ + return "ok"; + }finally{ + bus.post(RequestEvents.finish("get",1l)); + } + } + +} \ No newline at end of file diff --git a/micro-client/src/test/java/app/events/com/oath/micro/server/Job.java b/micro-client/src/test/java/app/events/com/oath/micro/server/Job.java new file mode 100644 index 000000000..f9457c509 --- /dev/null +++ b/micro-client/src/test/java/app/events/com/oath/micro/server/Job.java @@ -0,0 +1,16 @@ +package app.events.com.oath.micro.server; + +import org.springframework.stereotype.Component; + +import com.oath.micro.server.events.ScheduledJob; +import com.oath.micro.server.events.SystemData; + +@Component +public class Job implements ScheduledJob{ + + @Override + public SystemData scheduleAndLog() { + return SystemData.builder().errors(0).processed(2).build(); + } + +} diff --git a/micro-client/src/test/java/app/events/com/oath/micro/server/Schedular.java b/micro-client/src/test/java/app/events/com/oath/micro/server/Schedular.java new file mode 100644 index 000000000..c93a9c537 --- /dev/null +++ b/micro-client/src/test/java/app/events/com/oath/micro/server/Schedular.java @@ -0,0 +1,21 @@ +package app.events.com.oath.micro.server; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +@Component +public class Schedular { + + private final Job job; + + @Autowired + public Schedular(final Job job){ + this.job=job; + } + + @Scheduled(fixedDelay=1) + public synchronized void scheduleTask(){ + job.scheduleAndLog(); + } +} diff --git a/micro-client/src/test/java/app/rest/client/com/aol/micro/server/GenericRestClientResource.java b/micro-client/src/test/java/app/rest/client/com/aol/micro/server/GenericRestClientResource.java deleted file mode 100644 index 8aa6fdec9..000000000 --- a/micro-client/src/test/java/app/rest/client/com/aol/micro/server/GenericRestClientResource.java +++ /dev/null @@ -1,56 +0,0 @@ -package app.rest.client.com.aol.micro.server; - -import java.util.List; - -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.RestResource; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; - -@Component -@Path("/rest") -public class GenericRestClientResource implements RestResource { - - - @GET - @Produces("application/json") - @Path("/get") - public List get() { - - return ImmutableList.of("ok"); - } - - @POST - @Produces("application/json") - @Path("/post") - public ImmutableSet post(ImmutableMap map) { - - return ImmutableSet.copyOf(map.values()); - } - - @PUT - @Produces("application/json") - @Path("/put") - public ImmutableSet put(ImmutableMap map) { - - return ImmutableSet.copyOf(map.values()); - } - @DELETE - @Produces("application/json") - @Path("/delete") - public List delete(ImmutableMap map) { - - return ImmutableList.of("ok"); - } - - -} \ No newline at end of file diff --git a/micro-client/src/test/java/app/rest/client/com/aol/micro/server/MyEntity.java b/micro-client/src/test/java/app/rest/client/com/aol/micro/server/MyEntity.java deleted file mode 100644 index 1d2fa9b71..000000000 --- a/micro-client/src/test/java/app/rest/client/com/aol/micro/server/MyEntity.java +++ /dev/null @@ -1,12 +0,0 @@ -package app.rest.client.com.aol.micro.server; - -import lombok.EqualsAndHashCode; -import lombok.Getter; - -@EqualsAndHashCode -@Getter -public class MyEntity { - - private final String name ="myEntity"; - -} diff --git a/micro-client/src/test/java/app/rest/client/com/aol/micro/server/RestClientResource.java b/micro-client/src/test/java/app/rest/client/com/aol/micro/server/RestClientResource.java deleted file mode 100644 index c784b47d7..000000000 --- a/micro-client/src/test/java/app/rest/client/com/aol/micro/server/RestClientResource.java +++ /dev/null @@ -1,54 +0,0 @@ -package app.rest.client.com.aol.micro.server; - -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.RestResource; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; - -@Component -@Path("/generics") -public class RestClientResource implements RestResource { - - private final ImmutableList result = ImmutableList.of(new MyEntity()); - @GET - @Produces("application/json") - @Path("/get") - public ImmutableList get() { - - return result; - } - - @POST - @Produces("application/json") - @Path("/post") - public ImmutableList post(ImmutableMap map) { - - return result; - } - - @PUT - @Produces("application/json") - @Path("/put") - public ImmutableList put(ImmutableMap map) { - - return result; - } - @DELETE - @Produces("application/json") - @Path("/delete") - public ImmutableList delete(ImmutableMap map) { - - return result; - } - - -} \ No newline at end of file diff --git a/micro-client/src/test/java/app/rest/client/com/aol/micro/server/RestClientTest.java b/micro-client/src/test/java/app/rest/client/com/aol/micro/server/RestClientTest.java deleted file mode 100644 index 9d7dbcf5e..000000000 --- a/micro-client/src/test/java/app/rest/client/com/aol/micro/server/RestClientTest.java +++ /dev/null @@ -1,141 +0,0 @@ - -package app.rest.client.com.aol.micro.server; - - -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.assertThat; - -import java.net.URI; -import java.net.URISyntaxException; -import java.util.List; -import java.util.concurrent.ExecutionException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.springframework.core.ParameterizedTypeReference; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpMethod; -import org.springframework.web.client.RestClientException; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.rest.client.RestClient; -import com.aol.micro.server.rest.client.nio.AsyncRestClient; -import com.aol.micro.server.rest.client.nio.NIORestClient; -import com.aol.micro.server.rest.client.nio.SpringConfig; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; - -@Microserver -public class RestClientTest { - - private final AsyncRestClient> listClient = new AsyncRestClient(1000,1000).withResponse(List.class); - private final AsyncRestClient> setClient = new AsyncRestClient(1000,1000).withResponse(ImmutableSet.class);; - private final AsyncRestClient> genericsClient = new AsyncRestClient(1000,1000).withGenericResponse(ImmutableList.class, MyEntity.class); - - private final RestClient> listClientSync = new RestClient(1000,1000).withResponse(List.class); - private final RestClient> setClientSync = new RestClient(1000,1000).withResponse(ImmutableSet.class);; - private final RestClient> genericsClientSync = new RestClient(1000,1000).withGenericResponse(ImmutableList.class, MyEntity.class); - - private final NIORestClient rest = new SpringConfig().restClient(); - - - MicroserverApp server; - @Before - public void startServer(){ - - server = new MicroserverApp( RestClientTest.class, ()-> "rest-app"); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - /* - * Simpler with JaxRsNIOClient - */ - @Test - public void testCRUD() throws InterruptedException, ExecutionException{ - - - assertThat(listClient.get("http://localhost:8080/rest-app/rest/get").get().get(0),is("ok")); - assertThat(setClient.post("http://localhost:8080/rest-app/rest/post",ImmutableMap.of(1,"hello")).get(),is(ImmutableSet.of("hello"))); - assertThat(setClient.put("http://localhost:8080/rest-app/rest/put",ImmutableMap.of(1,"hello")).get(),is(ImmutableSet.of("hello"))); - assertThat(listClient.delete("http://localhost:8080/rest-app/rest/delete").get().get(0),is("ok")); - } - - @Test - public void testCRUDGenerics() throws InterruptedException, ExecutionException{ - - - assertThat(genericsClient.get("http://localhost:8080/rest-app/generics/get").get().get(0),is(new MyEntity())); - assertThat(genericsClient.post("http://localhost:8080/rest-app/generics/post",ImmutableMap.of(1,"hello")).get(),is(ImmutableList.of(new MyEntity()))); - assertThat(genericsClient.put("http://localhost:8080/rest-app/generics/put",ImmutableMap.of(1,"hello")).get(),is(ImmutableList.of(new MyEntity()))); - assertThat(genericsClient.delete("http://localhost:8080/rest-app/generics/delete").get().get(0),is(new MyEntity())); - } - /* - * Simpler with JaxRsNIOClient - */ - @Test - public void testCRUDSync() throws InterruptedException, ExecutionException{ - - - assertThat(listClientSync.get("http://localhost:8080/rest-app/rest/get").get(0),is("ok")); - assertThat(setClientSync.post("http://localhost:8080/rest-app/rest/post",ImmutableMap.of(1,"hello")),is(ImmutableSet.of("hello"))); - assertThat(setClientSync.put("http://localhost:8080/rest-app/rest/put",ImmutableMap.of(1,"hello")),is(ImmutableSet.of("hello"))); - assertThat(listClientSync.delete("http://localhost:8080/rest-app/rest/delete").get(0),is("ok")); - } - - @Test - public void testCRUDGenericsSync() throws InterruptedException, ExecutionException{ - - - assertThat(genericsClientSync.get("http://localhost:8080/rest-app/generics/get").get(0),is(new MyEntity())); - assertThat(genericsClientSync.post("http://localhost:8080/rest-app/generics/post",ImmutableMap.of(1,"hello")),is(ImmutableList.of(new MyEntity()))); - assertThat(genericsClientSync.put("http://localhost:8080/rest-app/generics/put",ImmutableMap.of(1,"hello")),is(ImmutableList.of(new MyEntity()))); - assertThat(genericsClientSync.delete("http://localhost:8080/rest-app/generics/delete").get(0),is(new MyEntity())); - } - - /** - * More complex with Spring REST Template Based NIORestTemplate - * - */ - - @Test - public void testCRUDSpring() throws InterruptedException, ExecutionException, RestClientException, URISyntaxException{ - - - assertThat(rest.getForEntity(new URI("http://localhost:8080/rest-app/rest/get"),List.class).get().getBody().get(0),is("ok")); - - assertThat(rest.postForEntity("http://localhost:8080/rest-app/rest/post", new HttpEntity(ImmutableMap.of(1,"hello")), ImmutableSet.class).get().getBody(),is(ImmutableSet.of("hello"))); - assertThat( rest.put("http://localhost:8080/rest-app/rest/put",new HttpEntity(ImmutableMap.of(1,"hello")),ImmutableSet.class).get() - ,is(nullValue())); - assertThat(rest.delete("http://localhost:8080/rest-app/rest/delete").get(),is(nullValue())); - } - - @Test - public void testCRUDGenericsSpring() throws InterruptedException, ExecutionException{ - - - assertThat(rest.exchange("http://localhost:8080/rest-app/generics/get",HttpMethod.GET,null,new ParameterizedTypeReference>(){}) - .get().getBody().get(0),is(new MyEntity())); - - assertThat(rest.exchange("http://localhost:8080/rest-app/generics/post",HttpMethod.POST,new HttpEntity(ImmutableMap.of(1,"hello")),new ParameterizedTypeReference>(){}) - .get().getBody(),is(ImmutableList.of(new MyEntity()))); - - assertThat(rest.exchange("http://localhost:8080/rest-app/generics/put",HttpMethod.PUT,new HttpEntity(ImmutableMap.of(1,"hello")),new ParameterizedTypeReference>(){}) - .get().getBody(),is(ImmutableList.of(new MyEntity()))); - - assertThat(rest.exchange("http://localhost:8080/rest-app/generics/delete",HttpMethod.DELETE,null,new ParameterizedTypeReference>(){}) - .get().getBody().get(0),is(new MyEntity())); - - } - - - -} diff --git a/micro-client/src/test/java/app/rest/client/com/oath/micro/server/GenericRestClientResource.java b/micro-client/src/test/java/app/rest/client/com/oath/micro/server/GenericRestClientResource.java new file mode 100644 index 000000000..3b6b9ee90 --- /dev/null +++ b/micro-client/src/test/java/app/rest/client/com/oath/micro/server/GenericRestClientResource.java @@ -0,0 +1,56 @@ +package app.rest.client.com.oath.micro.server; + +import java.util.List; + +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.RestResource; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; + +@Component +@Path("/rest") +public class GenericRestClientResource implements RestResource { + + + @GET + @Produces("application/json") + @Path("/get") + public List get() { + + return ImmutableList.of("ok"); + } + + @POST + @Produces("application/json") + @Path("/post") + public ImmutableSet post(ImmutableMap map) { + + return ImmutableSet.copyOf(map.values()); + } + + @PUT + @Produces("application/json") + @Path("/put") + public ImmutableSet put(ImmutableMap map) { + + return ImmutableSet.copyOf(map.values()); + } + @DELETE + @Produces("application/json") + @Path("/delete") + public List delete(ImmutableMap map) { + + return ImmutableList.of("ok"); + } + + +} \ No newline at end of file diff --git a/micro-client/src/test/java/app/rest/client/com/oath/micro/server/MyEntity.java b/micro-client/src/test/java/app/rest/client/com/oath/micro/server/MyEntity.java new file mode 100644 index 000000000..c075fa67f --- /dev/null +++ b/micro-client/src/test/java/app/rest/client/com/oath/micro/server/MyEntity.java @@ -0,0 +1,12 @@ +package app.rest.client.com.oath.micro.server; + +import lombok.EqualsAndHashCode; +import lombok.Getter; + +@EqualsAndHashCode +@Getter +public class MyEntity { + + private final String name ="myEntity"; + +} diff --git a/micro-client/src/test/java/app/rest/client/com/oath/micro/server/RestClientResource.java b/micro-client/src/test/java/app/rest/client/com/oath/micro/server/RestClientResource.java new file mode 100644 index 000000000..90c119ba5 --- /dev/null +++ b/micro-client/src/test/java/app/rest/client/com/oath/micro/server/RestClientResource.java @@ -0,0 +1,53 @@ +package app.rest.client.com.oath.micro.server; + +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.RestResource; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; + +@Component +@Path("/generics") +public class RestClientResource implements RestResource { + + private final ImmutableList result = ImmutableList.of(new MyEntity()); + @GET + @Produces("application/json") + @Path("/get") + public ImmutableList get() { + + return result; + } + + @POST + @Produces("application/json") + @Path("/post") + public ImmutableList post(ImmutableMap map) { + + return result; + } + + @PUT + @Produces("application/json") + @Path("/put") + public ImmutableList put(ImmutableMap map) { + + return result; + } + @DELETE + @Produces("application/json") + @Path("/delete") + public ImmutableList delete(ImmutableMap map) { + + return result; + } + + +} \ No newline at end of file diff --git a/micro-client/src/test/java/app/rest/client/com/oath/micro/server/RestClientTest.java b/micro-client/src/test/java/app/rest/client/com/oath/micro/server/RestClientTest.java new file mode 100644 index 000000000..d011e0235 --- /dev/null +++ b/micro-client/src/test/java/app/rest/client/com/oath/micro/server/RestClientTest.java @@ -0,0 +1,141 @@ + +package app.rest.client.com.oath.micro.server; + + +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.assertThat; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.List; +import java.util.concurrent.ExecutionException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpMethod; +import org.springframework.web.client.RestClientException; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.rest.client.RestClient; +import com.oath.micro.server.rest.client.nio.AsyncRestClient; +import com.oath.micro.server.rest.client.nio.NIORestClient; +import com.oath.micro.server.rest.client.nio.SpringConfig; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; + +@Microserver +public class RestClientTest { + + private final AsyncRestClient> listClient = new AsyncRestClient(1000,1000).withResponse(List.class); + private final AsyncRestClient> setClient = new AsyncRestClient(1000,1000).withResponse(ImmutableSet.class);; + private final AsyncRestClient> genericsClient = new AsyncRestClient(1000,1000).withGenericResponse(ImmutableList.class, MyEntity.class); + + private final RestClient> listClientSync = new RestClient(1000,1000).withResponse(List.class); + private final RestClient> setClientSync = new RestClient(1000,1000).withResponse(ImmutableSet.class);; + private final RestClient> genericsClientSync = new RestClient(1000,1000).withGenericResponse(ImmutableList.class, MyEntity.class); + + private final NIORestClient rest = new SpringConfig().restClient(); + + + MicroserverApp server; + @Before + public void startServer(){ + + server = new MicroserverApp( RestClientTest.class, ()-> "rest-app"); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + /* + * Simpler with JaxRsNIOClient + */ + @Test + public void testCRUD() throws InterruptedException, ExecutionException{ + + + assertThat(listClient.get("http://localhost:8080/rest-app/rest/get").get().get(0),is("ok")); + assertThat(setClient.post("http://localhost:8080/rest-app/rest/post",ImmutableMap.of(1,"hello")).get(),is(ImmutableSet.of("hello"))); + assertThat(setClient.put("http://localhost:8080/rest-app/rest/put",ImmutableMap.of(1,"hello")).get(),is(ImmutableSet.of("hello"))); + assertThat(listClient.delete("http://localhost:8080/rest-app/rest/delete").get().get(0),is("ok")); + } + + @Test + public void testCRUDGenerics() throws InterruptedException, ExecutionException{ + + + assertThat(genericsClient.get("http://localhost:8080/rest-app/generics/get").get().get(0),is(new MyEntity())); + assertThat(genericsClient.post("http://localhost:8080/rest-app/generics/post",ImmutableMap.of(1,"hello")).get(),is(ImmutableList.of(new MyEntity()))); + assertThat(genericsClient.put("http://localhost:8080/rest-app/generics/put",ImmutableMap.of(1,"hello")).get(),is(ImmutableList.of(new MyEntity()))); + assertThat(genericsClient.delete("http://localhost:8080/rest-app/generics/delete").get().get(0),is(new MyEntity())); + } + /* + * Simpler with JaxRsNIOClient + */ + @Test + public void testCRUDSync() throws InterruptedException, ExecutionException{ + + + assertThat(listClientSync.get("http://localhost:8080/rest-app/rest/get").get(0),is("ok")); + assertThat(setClientSync.post("http://localhost:8080/rest-app/rest/post",ImmutableMap.of(1,"hello")),is(ImmutableSet.of("hello"))); + assertThat(setClientSync.put("http://localhost:8080/rest-app/rest/put",ImmutableMap.of(1,"hello")),is(ImmutableSet.of("hello"))); + assertThat(listClientSync.delete("http://localhost:8080/rest-app/rest/delete").get(0),is("ok")); + } + + @Test + public void testCRUDGenericsSync() throws InterruptedException, ExecutionException{ + + + assertThat(genericsClientSync.get("http://localhost:8080/rest-app/generics/get").get(0),is(new MyEntity())); + assertThat(genericsClientSync.post("http://localhost:8080/rest-app/generics/post",ImmutableMap.of(1,"hello")),is(ImmutableList.of(new MyEntity()))); + assertThat(genericsClientSync.put("http://localhost:8080/rest-app/generics/put",ImmutableMap.of(1,"hello")),is(ImmutableList.of(new MyEntity()))); + assertThat(genericsClientSync.delete("http://localhost:8080/rest-app/generics/delete").get(0),is(new MyEntity())); + } + + /** + * More complex with Spring REST Template Based NIORestTemplate + * + */ + + @Test + public void testCRUDSpring() throws InterruptedException, ExecutionException, RestClientException, URISyntaxException{ + + + assertThat(rest.getForEntity(new URI("http://localhost:8080/rest-app/rest/get"),List.class).get().getBody().get(0),is("ok")); + + assertThat(rest.postForEntity("http://localhost:8080/rest-app/rest/post", new HttpEntity(ImmutableMap.of(1,"hello")), ImmutableSet.class).get().getBody(),is(ImmutableSet.of("hello"))); + assertThat( rest.put("http://localhost:8080/rest-app/rest/put",new HttpEntity(ImmutableMap.of(1,"hello")),ImmutableSet.class).get() + ,is(nullValue())); + assertThat(rest.delete("http://localhost:8080/rest-app/rest/delete").get(),is(nullValue())); + } + + @Test + public void testCRUDGenericsSpring() throws InterruptedException, ExecutionException{ + + + assertThat(rest.exchange("http://localhost:8080/rest-app/generics/get",HttpMethod.GET,null,new ParameterizedTypeReference>(){}) + .get().getBody().get(0),is(new MyEntity())); + + assertThat(rest.exchange("http://localhost:8080/rest-app/generics/post",HttpMethod.POST,new HttpEntity(ImmutableMap.of(1,"hello")),new ParameterizedTypeReference>(){}) + .get().getBody(),is(ImmutableList.of(new MyEntity()))); + + assertThat(rest.exchange("http://localhost:8080/rest-app/generics/put",HttpMethod.PUT,new HttpEntity(ImmutableMap.of(1,"hello")),new ParameterizedTypeReference>(){}) + .get().getBody(),is(ImmutableList.of(new MyEntity()))); + + assertThat(rest.exchange("http://localhost:8080/rest-app/generics/delete",HttpMethod.DELETE,null,new ParameterizedTypeReference>(){}) + .get().getBody().get(0),is(new MyEntity())); + + } + + + +} diff --git a/micro-client/src/test/java/com/aol/micro/server/client/TestPlugin.java b/micro-client/src/test/java/com/aol/micro/server/client/TestPlugin.java deleted file mode 100644 index 7588dd368..000000000 --- a/micro-client/src/test/java/com/aol/micro/server/client/TestPlugin.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.aol.micro.server.client; - - -import com.aol.micro.server.Plugin; -import cyclops.collections.immutable.LinkedListX; -import cyclops.collections.mutable.ListX; - -import java.util.List; - -public class TestPlugin implements Plugin { - public List providers(){ - return ListX.empty(); - } -} diff --git a/micro-client/src/test/java/com/aol/micro/server/testing/RestAgent.java b/micro-client/src/test/java/com/aol/micro/server/testing/RestAgent.java deleted file mode 100644 index ce204f810..000000000 --- a/micro-client/src/test/java/com/aol/micro/server/testing/RestAgent.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.aol.micro.server.testing; - -import java.util.List; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.Invocation.Builder; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; - -import com.aol.micro.server.rest.jackson.JacksonUtil; - -public class RestAgent { - - - public String getJson(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.get(String.class); - - } - - public String get(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.TEXT_PLAIN); - - return request.get(String.class); - - } - - public T post(String url, Object payload,Class type) { - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); - } - - -} diff --git a/micro-client/src/test/java/com/aol/micro/server/client/ClientModuleTest.java b/micro-client/src/test/java/com/oath/micro/server/client/ClientModuleTest.java similarity index 81% rename from micro-client/src/test/java/com/aol/micro/server/client/ClientModuleTest.java rename to micro-client/src/test/java/com/oath/micro/server/client/ClientModuleTest.java index 7b9aed833..a6acf5b58 100644 --- a/micro-client/src/test/java/com/aol/micro/server/client/ClientModuleTest.java +++ b/micro-client/src/test/java/com/oath/micro/server/client/ClientModuleTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.client; +package com.oath.micro.server.client; import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertThat; @@ -9,9 +9,9 @@ import org.junit.Test; -import com.aol.micro.server.Plugin; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.module.Module; +import com.oath.micro.server.Plugin; +import com.oath.micro.server.module.ConfigurableModule; +import com.oath.micro.server.module.Module; public class ClientModuleTest { @Test diff --git a/micro-client/src/test/java/com/oath/micro/server/client/TestPlugin.java b/micro-client/src/test/java/com/oath/micro/server/client/TestPlugin.java new file mode 100644 index 000000000..da5efc2de --- /dev/null +++ b/micro-client/src/test/java/com/oath/micro/server/client/TestPlugin.java @@ -0,0 +1,13 @@ +package com.oath.micro.server.client; + + +import com.oath.micro.server.Plugin; +import cyclops.collections.mutable.ListX; + +import java.util.List; + +public class TestPlugin implements Plugin { + public List providers(){ + return ListX.empty(); + } +} diff --git a/micro-client/src/test/java/com/oath/micro/server/testing/RestAgent.java b/micro-client/src/test/java/com/oath/micro/server/testing/RestAgent.java new file mode 100644 index 000000000..b2b86303e --- /dev/null +++ b/micro-client/src/test/java/com/oath/micro/server/testing/RestAgent.java @@ -0,0 +1,53 @@ +package com.oath.micro.server.testing; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.Invocation.Builder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; + +import com.oath.micro.server.rest.jackson.JacksonUtil; + +public class RestAgent { + + + public String getJson(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.get(String.class); + + } + + public String get(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.TEXT_PLAIN); + + return request.get(String.class); + + } + + public T post(String url, Object payload,Class type) { + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); + } + + +} diff --git a/micro-core/src/main/java/com/aol/micro/server/HealthStatusChecker.java b/micro-core/src/main/java/com/aol/micro/server/HealthStatusChecker.java deleted file mode 100644 index aba868156..000000000 --- a/micro-core/src/main/java/com/aol/micro/server/HealthStatusChecker.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.aol.micro.server; - -@FunctionalInterface -public interface HealthStatusChecker { - - boolean isOk(); -} diff --git a/micro-core/src/main/java/com/aol/micro/server/auto/discovery/CommonRestResource.java b/micro-core/src/main/java/com/aol/micro/server/auto/discovery/CommonRestResource.java deleted file mode 100644 index d78c15e36..000000000 --- a/micro-core/src/main/java/com/aol/micro/server/auto/discovery/CommonRestResource.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.aol.micro.server.auto.discovery; - -public interface CommonRestResource extends RestResource { - - -} diff --git a/micro-core/src/main/java/com/aol/micro/server/auto/discovery/RestResource.java b/micro-core/src/main/java/com/aol/micro/server/auto/discovery/RestResource.java deleted file mode 100644 index de2691293..000000000 --- a/micro-core/src/main/java/com/aol/micro/server/auto/discovery/RestResource.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.aol.micro.server.auto.discovery; - - - -public interface RestResource { - - /** - * @return true if singleton - */ - default boolean isSingleton(){ - return false; - } - -} diff --git a/micro-core/src/main/java/com/aol/micro/server/auto/discovery/SingletonRestResource.java b/micro-core/src/main/java/com/aol/micro/server/auto/discovery/SingletonRestResource.java deleted file mode 100644 index 5488946d2..000000000 --- a/micro-core/src/main/java/com/aol/micro/server/auto/discovery/SingletonRestResource.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.aol.micro.server.auto.discovery; - -public interface SingletonRestResource extends RestResource{ - default boolean isSingleton(){ - return true; - } -} diff --git a/micro-core/src/main/java/com/aol/micro/server/config/Classes.java b/micro-core/src/main/java/com/aol/micro/server/config/Classes.java deleted file mode 100644 index fa1eaed2f..000000000 --- a/micro-core/src/main/java/com/aol/micro/server/config/Classes.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.aol.micro.server.config; - -import java.util.ArrayList; -import java.util.List; - -import lombok.Getter; -import nonautoscan.com.aol.micro.server.AopConfig; -import nonautoscan.com.aol.micro.server.SSLConfig; -import nonautoscan.com.aol.micro.server.ScheduleAndAsyncConfig; - -import com.aol.micro.server.module.ConfigureEnviroment; -import com.aol.micro.server.servers.AccessLogConfig; -import com.aol.micro.server.spring.properties.PropertyFileConfig; - -/** - * - * Collections of Spring configuration classes (Classes annotated with @Configuration) - * that configure various useful pieces of functionality - such as property file loading, - * datasources, scheduling etc - * - * @author johnmcclean - * - */ -public class Classes { - - /** - * CORE CLASSES are the Core Microserver Spring Configuration classes - * Property support, Guava Event Bus, Spring AOP & Scheduling - * Codahale Metrics, Event tracking etc - */ - public static final Classes CORE_CLASSES = new Classes(PropertyFileConfig.class, AopConfig.class, - ScheduleAndAsyncConfig.class, ConfigureEnviroment.class, AccessLogConfig.class, SSLConfig.class); - - - @Getter - private final Class[] classes; - - public Classes(Class... classes) { - this.classes = classes; - } - - public Classes combine(Classes c){ - List c1 = new ArrayList<>(); - for(Class next : classes) - c1.add(next); - for(Class next : c.classes) - c1.add(next); - return new Classes(c1.toArray(new Class[0])); - } -} diff --git a/micro-core/src/main/java/com/aol/micro/server/config/Configurer.java b/micro-core/src/main/java/com/aol/micro/server/config/Configurer.java deleted file mode 100644 index 09baf2038..000000000 --- a/micro-core/src/main/java/com/aol/micro/server/config/Configurer.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.aol.micro.server.config; - -public interface Configurer { - public Config buildConfig(Class class1); -} diff --git a/micro-core/src/main/java/com/aol/micro/server/servers/ApplicationRegister.java b/micro-core/src/main/java/com/aol/micro/server/servers/ApplicationRegister.java deleted file mode 100644 index 37d2b7f5d..000000000 --- a/micro-core/src/main/java/com/aol/micro/server/servers/ApplicationRegister.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.aol.micro.server.servers; - -import com.aol.micro.server.servers.model.ServerData; - -public interface ApplicationRegister { - - void register(ServerData[] array); - -} diff --git a/micro-core/src/main/java/com/aol/micro/server/servers/ServerApplication.java b/micro-core/src/main/java/com/aol/micro/server/servers/ServerApplication.java deleted file mode 100644 index 94075c015..000000000 --- a/micro-core/src/main/java/com/aol/micro/server/servers/ServerApplication.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.aol.micro.server.servers; - -import java.util.concurrent.CompletableFuture; - -import com.aol.micro.server.config.SSLProperties; -import com.aol.micro.server.servers.model.ServerData; - -public interface ServerApplication { - void run(CompletableFuture start, JaxRsServletConfigurer jaxRsConfigurer, CompletableFuture end); - ServerData getServerData(); -} diff --git a/micro-core/src/main/java/com/aol/micro/server/servers/ServerApplicationFactory.java b/micro-core/src/main/java/com/aol/micro/server/servers/ServerApplicationFactory.java deleted file mode 100644 index 2950a8355..000000000 --- a/micro-core/src/main/java/com/aol/micro/server/servers/ServerApplicationFactory.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.aol.micro.server.servers; - -import org.springframework.context.ApplicationContext; - -import com.aol.micro.server.module.Module; - -public interface ServerApplicationFactory { - - public ServerApplication createApp(Module module,ApplicationContext springContext); -} diff --git a/micro-core/src/main/java/com/aol/micro/server/spring/SpringBuilder.java b/micro-core/src/main/java/com/aol/micro/server/spring/SpringBuilder.java deleted file mode 100644 index 284ac936e..000000000 --- a/micro-core/src/main/java/com/aol/micro/server/spring/SpringBuilder.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.aol.micro.server.spring; - -import org.springframework.context.ConfigurableApplicationContext; - -import com.aol.micro.server.config.Config; - -public interface SpringBuilder { - public ConfigurableApplicationContext createSpringApp(Config config, Class...classes); -} diff --git a/micro-core/src/main/java/com/aol/micro/server/GlobalState.java b/micro-core/src/main/java/com/oath/micro/server/GlobalState.java similarity index 78% rename from micro-core/src/main/java/com/aol/micro/server/GlobalState.java rename to micro-core/src/main/java/com/oath/micro/server/GlobalState.java index b25ed260a..591999894 100644 --- a/micro-core/src/main/java/com/aol/micro/server/GlobalState.java +++ b/micro-core/src/main/java/com/oath/micro/server/GlobalState.java @@ -1,7 +1,7 @@ -package com.aol.micro.server; +package com.oath.micro.server; -import com.aol.micro.server.module.Module; +import com.oath.micro.server.module.Module; import cyclops.collections.mutable.ListX; import lombok.Getter; diff --git a/micro-core/src/main/java/com/oath/micro/server/HealthStatusChecker.java b/micro-core/src/main/java/com/oath/micro/server/HealthStatusChecker.java new file mode 100644 index 000000000..870727fb3 --- /dev/null +++ b/micro-core/src/main/java/com/oath/micro/server/HealthStatusChecker.java @@ -0,0 +1,7 @@ +package com.oath.micro.server; + +@FunctionalInterface +public interface HealthStatusChecker { + + boolean isOk(); +} diff --git a/micro-core/src/main/java/com/aol/micro/server/IncorrectNumberOfServersConfiguredException.java b/micro-core/src/main/java/com/oath/micro/server/IncorrectNumberOfServersConfiguredException.java similarity index 85% rename from micro-core/src/main/java/com/aol/micro/server/IncorrectNumberOfServersConfiguredException.java rename to micro-core/src/main/java/com/oath/micro/server/IncorrectNumberOfServersConfiguredException.java index c73269302..d69afcf37 100644 --- a/micro-core/src/main/java/com/aol/micro/server/IncorrectNumberOfServersConfiguredException.java +++ b/micro-core/src/main/java/com/oath/micro/server/IncorrectNumberOfServersConfiguredException.java @@ -1,4 +1,4 @@ -package com.aol.micro.server; +package com.oath.micro.server; public class IncorrectNumberOfServersConfiguredException extends RuntimeException { diff --git a/micro-core/src/main/java/com/aol/micro/server/InternalErrorCode.java b/micro-core/src/main/java/com/oath/micro/server/InternalErrorCode.java similarity index 85% rename from micro-core/src/main/java/com/aol/micro/server/InternalErrorCode.java rename to micro-core/src/main/java/com/oath/micro/server/InternalErrorCode.java index 659127dc8..5480a401d 100644 --- a/micro-core/src/main/java/com/aol/micro/server/InternalErrorCode.java +++ b/micro-core/src/main/java/com/oath/micro/server/InternalErrorCode.java @@ -1,4 +1,4 @@ -package com.aol.micro.server; +package com.oath.micro.server; import lombok.Getter; diff --git a/micro-core/src/main/java/com/aol/micro/server/MicroserverApp.java b/micro-core/src/main/java/com/oath/micro/server/MicroserverApp.java similarity index 93% rename from micro-core/src/main/java/com/aol/micro/server/MicroserverApp.java rename to micro-core/src/main/java/com/oath/micro/server/MicroserverApp.java index 3318e8e0d..e0f584adf 100644 --- a/micro-core/src/main/java/com/aol/micro/server/MicroserverApp.java +++ b/micro-core/src/main/java/com/oath/micro/server/MicroserverApp.java @@ -1,4 +1,4 @@ -package com.aol.micro.server; +package com.oath.micro.server; import java.util.List; import java.util.concurrent.CompletableFuture; @@ -13,14 +13,14 @@ import org.springframework.context.ApplicationContext; -import com.aol.micro.server.config.Config; -import com.aol.micro.server.config.MicroserverConfigurer; -import com.aol.micro.server.module.Module; -import com.aol.micro.server.servers.ApplicationRegister; -import com.aol.micro.server.servers.ServerApplication; -import com.aol.micro.server.servers.ServerApplicationFactory; -import com.aol.micro.server.servers.ServerRunner; -import com.aol.micro.server.spring.SpringContextFactory; +import com.oath.micro.server.config.Config; +import com.oath.micro.server.config.MicroserverConfigurer; +import com.oath.micro.server.module.Module; +import com.oath.micro.server.servers.ApplicationRegister; +import com.oath.micro.server.servers.ServerApplication; +import com.oath.micro.server.servers.ServerApplicationFactory; +import com.oath.micro.server.servers.ServerRunner; +import com.oath.micro.server.spring.SpringContextFactory; import lombok.Getter; diff --git a/micro-core/src/main/java/com/aol/micro/server/Plugin.java b/micro-core/src/main/java/com/oath/micro/server/Plugin.java similarity index 86% rename from micro-core/src/main/java/com/aol/micro/server/Plugin.java rename to micro-core/src/main/java/com/oath/micro/server/Plugin.java index 71571a57a..ceff5bf3b 100644 --- a/micro-core/src/main/java/com/aol/micro/server/Plugin.java +++ b/micro-core/src/main/java/com/oath/micro/server/Plugin.java @@ -1,4 +1,4 @@ -package com.aol.micro.server; +package com.oath.micro.server; import java.util.List; import java.util.Map; @@ -13,22 +13,19 @@ import javax.ws.rs.core.FeatureContext; -import com.aol.micro.server.rest.RestConfiguration; -import com.aol.micro.server.servers.ServerApplicationFactory; -import com.aol.micro.server.servers.model.ServerData; -import com.aol.micro.server.spring.SpringBuilder; -import com.aol.micro.server.spring.SpringDBConfig; +import com.oath.micro.server.rest.RestConfiguration; +import com.oath.micro.server.servers.ServerApplicationFactory; +import com.oath.micro.server.servers.model.ServerData; +import com.oath.micro.server.spring.SpringBuilder; +import com.oath.micro.server.spring.SpringDBConfig; import com.fasterxml.jackson.databind.Module; -import cyclops.collections.immutable.PersistentMapX; -import cyclops.collections.immutable.PersistentSetX; -import cyclops.collections.immutable.LinkedListX; import cyclops.collections.mutable.ListX; import cyclops.collections.mutable.MapX; import cyclops.collections.mutable.SetX; /** * To implement a plugin for Microserver, implement this interface in your library and add the fully resolved class name to - * META-INF/services/com.aol.micro.server.Plugin + * META-INF/services/com.oath.micro.server.Plugin * * in your library * diff --git a/micro-core/src/main/java/com/aol/micro/server/PluginLoader.java b/micro-core/src/main/java/com/oath/micro/server/PluginLoader.java similarity index 95% rename from micro-core/src/main/java/com/aol/micro/server/PluginLoader.java rename to micro-core/src/main/java/com/oath/micro/server/PluginLoader.java index 254638760..580f2baf4 100644 --- a/micro-core/src/main/java/com/aol/micro/server/PluginLoader.java +++ b/micro-core/src/main/java/com/oath/micro/server/PluginLoader.java @@ -1,4 +1,4 @@ -package com.aol.micro.server; +package com.oath.micro.server; import java.util.ServiceLoader; import java.util.function.Supplier; diff --git a/micro-core/src/main/java/com/aol/micro/server/SchedulingConfiguration.java b/micro-core/src/main/java/com/oath/micro/server/SchedulingConfiguration.java similarity index 88% rename from micro-core/src/main/java/com/aol/micro/server/SchedulingConfiguration.java rename to micro-core/src/main/java/com/oath/micro/server/SchedulingConfiguration.java index ec4b5943b..017929e57 100644 --- a/micro-core/src/main/java/com/aol/micro/server/SchedulingConfiguration.java +++ b/micro-core/src/main/java/com/oath/micro/server/SchedulingConfiguration.java @@ -1,4 +1,4 @@ -package com.aol.micro.server; +package com.oath.micro.server; import org.springframework.scheduling.annotation.AsyncConfigurer; import org.springframework.scheduling.annotation.SchedulingConfigurer; diff --git a/micro-core/src/main/java/com/aol/micro/server/StatsSupplier.java b/micro-core/src/main/java/com/oath/micro/server/StatsSupplier.java similarity index 82% rename from micro-core/src/main/java/com/aol/micro/server/StatsSupplier.java rename to micro-core/src/main/java/com/oath/micro/server/StatsSupplier.java index ec4378eab..c469af339 100644 --- a/micro-core/src/main/java/com/aol/micro/server/StatsSupplier.java +++ b/micro-core/src/main/java/com/oath/micro/server/StatsSupplier.java @@ -1,4 +1,4 @@ -package com.aol.micro.server; +package com.oath.micro.server; import java.util.Map; import java.util.function.Supplier; diff --git a/micro-core/src/main/java/com/aol/micro/server/WorkerThreads.java b/micro-core/src/main/java/com/oath/micro/server/WorkerThreads.java similarity index 93% rename from micro-core/src/main/java/com/aol/micro/server/WorkerThreads.java rename to micro-core/src/main/java/com/oath/micro/server/WorkerThreads.java index 6b3ff8e2c..97ae38fb5 100644 --- a/micro-core/src/main/java/com/aol/micro/server/WorkerThreads.java +++ b/micro-core/src/main/java/com/oath/micro/server/WorkerThreads.java @@ -1,4 +1,4 @@ -package com.aol.micro.server; +package com.oath.micro.server; import cyclops.function.FluentFunctions; diff --git a/micro-core/src/main/java/com/aol/micro/server/auto/discovery/AutoFilterConfiguration.java b/micro-core/src/main/java/com/oath/micro/server/auto/discovery/AutoFilterConfiguration.java similarity index 84% rename from micro-core/src/main/java/com/aol/micro/server/auto/discovery/AutoFilterConfiguration.java rename to micro-core/src/main/java/com/oath/micro/server/auto/discovery/AutoFilterConfiguration.java index 059d21e4f..344d22f15 100644 --- a/micro-core/src/main/java/com/aol/micro/server/auto/discovery/AutoFilterConfiguration.java +++ b/micro-core/src/main/java/com/oath/micro/server/auto/discovery/AutoFilterConfiguration.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.auto.discovery; +package com.oath.micro.server.auto.discovery; import cyclops.control.Either; diff --git a/micro-core/src/main/java/com/aol/micro/server/auto/discovery/AutoServletConfiguration.java b/micro-core/src/main/java/com/oath/micro/server/auto/discovery/AutoServletConfiguration.java similarity index 87% rename from micro-core/src/main/java/com/aol/micro/server/auto/discovery/AutoServletConfiguration.java rename to micro-core/src/main/java/com/oath/micro/server/auto/discovery/AutoServletConfiguration.java index f88b16f06..ae94663f8 100644 --- a/micro-core/src/main/java/com/aol/micro/server/auto/discovery/AutoServletConfiguration.java +++ b/micro-core/src/main/java/com/oath/micro/server/auto/discovery/AutoServletConfiguration.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.auto.discovery; +package com.oath.micro.server.auto.discovery; import cyclops.control.Either; diff --git a/micro-core/src/main/java/com/oath/micro/server/auto/discovery/CommonRestResource.java b/micro-core/src/main/java/com/oath/micro/server/auto/discovery/CommonRestResource.java new file mode 100644 index 000000000..69b502ce9 --- /dev/null +++ b/micro-core/src/main/java/com/oath/micro/server/auto/discovery/CommonRestResource.java @@ -0,0 +1,6 @@ +package com.oath.micro.server.auto.discovery; + +public interface CommonRestResource extends RestResource { + + +} diff --git a/micro-core/src/main/java/com/aol/micro/server/auto/discovery/FilterConfiguration.java b/micro-core/src/main/java/com/oath/micro/server/auto/discovery/FilterConfiguration.java similarity index 95% rename from micro-core/src/main/java/com/aol/micro/server/auto/discovery/FilterConfiguration.java rename to micro-core/src/main/java/com/oath/micro/server/auto/discovery/FilterConfiguration.java index f2d782aec..e42598fc2 100644 --- a/micro-core/src/main/java/com/aol/micro/server/auto/discovery/FilterConfiguration.java +++ b/micro-core/src/main/java/com/oath/micro/server/auto/discovery/FilterConfiguration.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.auto.discovery; +package com.oath.micro.server.auto.discovery; import java.util.HashMap; import java.util.Map; diff --git a/micro-core/src/main/java/com/aol/micro/server/auto/discovery/JaxRsResource.java b/micro-core/src/main/java/com/oath/micro/server/auto/discovery/JaxRsResource.java similarity index 87% rename from micro-core/src/main/java/com/aol/micro/server/auto/discovery/JaxRsResource.java rename to micro-core/src/main/java/com/oath/micro/server/auto/discovery/JaxRsResource.java index f5bb3715c..1ce944b75 100644 --- a/micro-core/src/main/java/com/aol/micro/server/auto/discovery/JaxRsResource.java +++ b/micro-core/src/main/java/com/oath/micro/server/auto/discovery/JaxRsResource.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.auto.discovery; +package com.oath.micro.server.auto.discovery; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/micro-core/src/main/java/com/aol/micro/server/auto/discovery/JaxRsResourceWrapper.java b/micro-core/src/main/java/com/oath/micro/server/auto/discovery/JaxRsResourceWrapper.java similarity index 85% rename from micro-core/src/main/java/com/aol/micro/server/auto/discovery/JaxRsResourceWrapper.java rename to micro-core/src/main/java/com/oath/micro/server/auto/discovery/JaxRsResourceWrapper.java index 31eeb7d5e..8c0ba7bd5 100644 --- a/micro-core/src/main/java/com/aol/micro/server/auto/discovery/JaxRsResourceWrapper.java +++ b/micro-core/src/main/java/com/oath/micro/server/auto/discovery/JaxRsResourceWrapper.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.auto.discovery; +package com.oath.micro.server.auto.discovery; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/micro-core/src/main/java/com/aol/micro/server/auto/discovery/Rest.java b/micro-core/src/main/java/com/oath/micro/server/auto/discovery/Rest.java similarity index 88% rename from micro-core/src/main/java/com/aol/micro/server/auto/discovery/Rest.java rename to micro-core/src/main/java/com/oath/micro/server/auto/discovery/Rest.java index bf8fe1a64..b5f4edbf6 100644 --- a/micro-core/src/main/java/com/aol/micro/server/auto/discovery/Rest.java +++ b/micro-core/src/main/java/com/oath/micro/server/auto/discovery/Rest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.auto.discovery; +package com.oath.micro.server.auto.discovery; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/micro-core/src/main/java/com/oath/micro/server/auto/discovery/RestResource.java b/micro-core/src/main/java/com/oath/micro/server/auto/discovery/RestResource.java new file mode 100644 index 000000000..c8ea08d55 --- /dev/null +++ b/micro-core/src/main/java/com/oath/micro/server/auto/discovery/RestResource.java @@ -0,0 +1,14 @@ +package com.oath.micro.server.auto.discovery; + + + +public interface RestResource { + + /** + * @return true if singleton + */ + default boolean isSingleton(){ + return false; + } + +} diff --git a/micro-core/src/main/java/com/aol/micro/server/auto/discovery/ServletConfiguration.java b/micro-core/src/main/java/com/oath/micro/server/auto/discovery/ServletConfiguration.java similarity index 95% rename from micro-core/src/main/java/com/aol/micro/server/auto/discovery/ServletConfiguration.java rename to micro-core/src/main/java/com/oath/micro/server/auto/discovery/ServletConfiguration.java index aed7aa938..0285ff0e8 100644 --- a/micro-core/src/main/java/com/aol/micro/server/auto/discovery/ServletConfiguration.java +++ b/micro-core/src/main/java/com/oath/micro/server/auto/discovery/ServletConfiguration.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.auto.discovery; +package com.oath.micro.server.auto.discovery; import java.util.HashMap; import java.util.Map; diff --git a/micro-core/src/main/java/com/oath/micro/server/auto/discovery/SingletonRestResource.java b/micro-core/src/main/java/com/oath/micro/server/auto/discovery/SingletonRestResource.java new file mode 100644 index 000000000..696ffc7db --- /dev/null +++ b/micro-core/src/main/java/com/oath/micro/server/auto/discovery/SingletonRestResource.java @@ -0,0 +1,7 @@ +package com.oath.micro.server.auto.discovery; + +public interface SingletonRestResource extends RestResource{ + default boolean isSingleton(){ + return true; + } +} diff --git a/micro-core/src/main/java/com/oath/micro/server/config/Classes.java b/micro-core/src/main/java/com/oath/micro/server/config/Classes.java new file mode 100644 index 000000000..fcade1ea5 --- /dev/null +++ b/micro-core/src/main/java/com/oath/micro/server/config/Classes.java @@ -0,0 +1,50 @@ +package com.oath.micro.server.config; + +import java.util.ArrayList; +import java.util.List; + +import lombok.Getter; +import nonautoscan.com.oath.micro.server.AopConfig; +import nonautoscan.com.oath.micro.server.SSLConfig; +import nonautoscan.com.oath.micro.server.ScheduleAndAsyncConfig; + +import com.oath.micro.server.module.ConfigureEnviroment; +import com.oath.micro.server.servers.AccessLogConfig; +import com.oath.micro.server.spring.properties.PropertyFileConfig; + +/** + * + * Collections of Spring configuration classes (Classes annotated with @Configuration) + * that configure various useful pieces of functionality - such as property file loading, + * datasources, scheduling etc + * + * @author johnmcclean + * + */ +public class Classes { + + /** + * CORE CLASSES are the Core Microserver Spring Configuration classes + * Property support, Guava Event Bus, Spring AOP & Scheduling + * Codahale Metrics, Event tracking etc + */ + public static final Classes CORE_CLASSES = new Classes(PropertyFileConfig.class, AopConfig.class, + ScheduleAndAsyncConfig.class, ConfigureEnviroment.class, AccessLogConfig.class, SSLConfig.class); + + + @Getter + private final Class[] classes; + + public Classes(Class... classes) { + this.classes = classes; + } + + public Classes combine(Classes c){ + List c1 = new ArrayList<>(); + for(Class next : classes) + c1.add(next); + for(Class next : c.classes) + c1.add(next); + return new Classes(c1.toArray(new Class[0])); + } +} diff --git a/micro-core/src/main/java/com/aol/micro/server/config/Config.java b/micro-core/src/main/java/com/oath/micro/server/config/Config.java similarity index 96% rename from micro-core/src/main/java/com/aol/micro/server/config/Config.java rename to micro-core/src/main/java/com/oath/micro/server/config/Config.java index 384c7e4b1..3659b0c25 100644 --- a/micro-core/src/main/java/com/aol/micro/server/config/Config.java +++ b/micro-core/src/main/java/com/oath/micro/server/config/Config.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.config; +package com.oath.micro.server.config; import java.util.Arrays; @@ -7,9 +7,6 @@ import com.oath.cyclops.types.persistent.PersistentSet; import cyclops.data.*; import java.util.List; -import java.util.Map; -import java.util.Set; - import lombok.AllArgsConstructor; diff --git a/micro-core/src/main/java/com/aol/micro/server/config/ConfigAccessor.java b/micro-core/src/main/java/com/oath/micro/server/config/ConfigAccessor.java similarity index 85% rename from micro-core/src/main/java/com/aol/micro/server/config/ConfigAccessor.java rename to micro-core/src/main/java/com/oath/micro/server/config/ConfigAccessor.java index ab40e66b3..e8fa1984f 100644 --- a/micro-core/src/main/java/com/aol/micro/server/config/ConfigAccessor.java +++ b/micro-core/src/main/java/com/oath/micro/server/config/ConfigAccessor.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.config; +package com.oath.micro.server.config; import java.util.function.Supplier; diff --git a/micro-core/src/main/java/com/oath/micro/server/config/Configurer.java b/micro-core/src/main/java/com/oath/micro/server/config/Configurer.java new file mode 100644 index 000000000..95500ae61 --- /dev/null +++ b/micro-core/src/main/java/com/oath/micro/server/config/Configurer.java @@ -0,0 +1,5 @@ +package com.oath.micro.server.config; + +public interface Configurer { + public Config buildConfig(Class class1); +} diff --git a/micro-core/src/main/java/com/aol/micro/server/config/Microserver.java b/micro-core/src/main/java/com/oath/micro/server/config/Microserver.java similarity index 97% rename from micro-core/src/main/java/com/aol/micro/server/config/Microserver.java rename to micro-core/src/main/java/com/oath/micro/server/config/Microserver.java index 312227a6b..52bf48abd 100644 --- a/micro-core/src/main/java/com/aol/micro/server/config/Microserver.java +++ b/micro-core/src/main/java/com/oath/micro/server/config/Microserver.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.config; +package com.oath.micro.server.config; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/micro-core/src/main/java/com/aol/micro/server/config/MicroserverConfigurer.java b/micro-core/src/main/java/com/oath/micro/server/config/MicroserverConfigurer.java similarity index 93% rename from micro-core/src/main/java/com/aol/micro/server/config/MicroserverConfigurer.java rename to micro-core/src/main/java/com/oath/micro/server/config/MicroserverConfigurer.java index 651eb33fa..8b7ee4c7e 100644 --- a/micro-core/src/main/java/com/aol/micro/server/config/MicroserverConfigurer.java +++ b/micro-core/src/main/java/com/oath/micro/server/config/MicroserverConfigurer.java @@ -1,9 +1,8 @@ -package com.aol.micro.server.config; +package com.oath.micro.server.config; -import com.aol.micro.server.Plugin; -import com.aol.micro.server.PluginLoader; +import com.oath.micro.server.Plugin; +import com.oath.micro.server.PluginLoader; import cyclops.data.HashMap; -import cyclops.data.HashSet; import cyclops.reactive.ReactiveSeq; diff --git a/micro-core/src/main/java/com/aol/micro/server/config/SSLProperties.java b/micro-core/src/main/java/com/oath/micro/server/config/SSLProperties.java similarity index 97% rename from micro-core/src/main/java/com/aol/micro/server/config/SSLProperties.java rename to micro-core/src/main/java/com/oath/micro/server/config/SSLProperties.java index 476be1035..8c6f0e458 100644 --- a/micro-core/src/main/java/com/aol/micro/server/config/SSLProperties.java +++ b/micro-core/src/main/java/com/oath/micro/server/config/SSLProperties.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.config; +package com.oath.micro.server.config; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/micro-core/src/main/java/com/aol/micro/server/module/ConfigurableModule.java b/micro-core/src/main/java/com/oath/micro/server/module/ConfigurableModule.java similarity index 94% rename from micro-core/src/main/java/com/aol/micro/server/module/ConfigurableModule.java rename to micro-core/src/main/java/com/oath/micro/server/module/ConfigurableModule.java index b1b70df80..891708438 100644 --- a/micro-core/src/main/java/com/aol/micro/server/module/ConfigurableModule.java +++ b/micro-core/src/main/java/com/oath/micro/server/module/ConfigurableModule.java @@ -1,12 +1,11 @@ -package com.aol.micro.server.module; +package com.oath.micro.server.module; -import static com.aol.micro.server.utility.UsefulStaticMethods.concat; +import static com.oath.micro.server.utility.UsefulStaticMethods.concat; import java.lang.annotation.Annotation; import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -18,14 +17,10 @@ import javax.servlet.ServletContextListener; import javax.servlet.ServletRequestListener; -import com.aol.micro.server.auto.discovery.CommonRestResource; -import com.aol.micro.server.servers.model.ServerData; -import com.aol.micro.server.utility.HashMapBuilder; +import com.oath.micro.server.auto.discovery.CommonRestResource; +import com.oath.micro.server.servers.model.ServerData; import com.oath.cyclops.types.persistent.PersistentMap; -import cyclops.collections.immutable.PersistentMapX; -import cyclops.collections.immutable.PersistentSetX; -import cyclops.collections.immutable.LinkedListX; import cyclops.collections.mutable.ListX; import cyclops.collections.mutable.MapX; import cyclops.collections.mutable.SetX; diff --git a/micro-core/src/main/java/com/aol/micro/server/module/ConfigureEnviroment.java b/micro-core/src/main/java/com/oath/micro/server/module/ConfigureEnviroment.java similarity index 94% rename from micro-core/src/main/java/com/aol/micro/server/module/ConfigureEnviroment.java rename to micro-core/src/main/java/com/oath/micro/server/module/ConfigureEnviroment.java index 5429b1d64..01d5df8e1 100644 --- a/micro-core/src/main/java/com/aol/micro/server/module/ConfigureEnviroment.java +++ b/micro-core/src/main/java/com/oath/micro/server/module/ConfigureEnviroment.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.module; +package com.oath.micro.server.module; import java.util.Collection; import java.util.Properties; diff --git a/micro-core/src/main/java/com/aol/micro/server/module/EmbeddedModule.java b/micro-core/src/main/java/com/oath/micro/server/module/EmbeddedModule.java similarity index 92% rename from micro-core/src/main/java/com/aol/micro/server/module/EmbeddedModule.java rename to micro-core/src/main/java/com/oath/micro/server/module/EmbeddedModule.java index 3cba716d2..a2dd13606 100644 --- a/micro-core/src/main/java/com/aol/micro/server/module/EmbeddedModule.java +++ b/micro-core/src/main/java/com/oath/micro/server/module/EmbeddedModule.java @@ -1,9 +1,8 @@ -package com.aol.micro.server.module; +package com.oath.micro.server.module; import java.lang.annotation.Annotation; -import cyclops.collections.immutable.PersistentSetX; import cyclops.collections.mutable.SetX; import lombok.Getter; @Getter diff --git a/micro-core/src/main/java/com/aol/micro/server/module/Environment.java b/micro-core/src/main/java/com/oath/micro/server/module/Environment.java similarity index 91% rename from micro-core/src/main/java/com/aol/micro/server/module/Environment.java rename to micro-core/src/main/java/com/oath/micro/server/module/Environment.java index 61f4b8f4a..f929c5af5 100644 --- a/micro-core/src/main/java/com/aol/micro/server/module/Environment.java +++ b/micro-core/src/main/java/com/oath/micro/server/module/Environment.java @@ -1,17 +1,14 @@ -package com.aol.micro.server.module; +package com.oath.micro.server.module; import java.net.InetAddress; import java.util.Collection; import cyclops.data.HashMap; -import java.util.Map; + import java.util.Optional; import java.util.Properties; -import java.util.stream.Collectors; import com.oath.cyclops.types.persistent.PersistentMap; import cyclops.control.Try; -import cyclops.data.tuple.Tuple; -import cyclops.reactive.ReactiveSeq; import static cyclops.data.tuple.Tuple.tuple; diff --git a/micro-core/src/main/java/com/aol/micro/server/module/IncorrectJaxRsPluginsException.java b/micro-core/src/main/java/com/oath/micro/server/module/IncorrectJaxRsPluginsException.java similarity index 80% rename from micro-core/src/main/java/com/aol/micro/server/module/IncorrectJaxRsPluginsException.java rename to micro-core/src/main/java/com/oath/micro/server/module/IncorrectJaxRsPluginsException.java index 45c90db30..ba1c81bee 100644 --- a/micro-core/src/main/java/com/aol/micro/server/module/IncorrectJaxRsPluginsException.java +++ b/micro-core/src/main/java/com/oath/micro/server/module/IncorrectJaxRsPluginsException.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.module; +package com.oath.micro.server.module; public class IncorrectJaxRsPluginsException extends RuntimeException { diff --git a/micro-core/src/main/java/com/aol/micro/server/module/JaxRsProvider.java b/micro-core/src/main/java/com/oath/micro/server/module/JaxRsProvider.java similarity index 83% rename from micro-core/src/main/java/com/aol/micro/server/module/JaxRsProvider.java rename to micro-core/src/main/java/com/oath/micro/server/module/JaxRsProvider.java index 1a0164728..04e7d3da4 100644 --- a/micro-core/src/main/java/com/aol/micro/server/module/JaxRsProvider.java +++ b/micro-core/src/main/java/com/oath/micro/server/module/JaxRsProvider.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.module; +package com.oath.micro.server.module; import lombok.AllArgsConstructor; diff --git a/micro-core/src/main/java/com/aol/micro/server/module/Module.java b/micro-core/src/main/java/com/oath/micro/server/module/Module.java similarity index 91% rename from micro-core/src/main/java/com/aol/micro/server/module/Module.java rename to micro-core/src/main/java/com/oath/micro/server/module/Module.java index 366d2e85c..b9f9d011e 100644 --- a/micro-core/src/main/java/com/aol/micro/server/module/Module.java +++ b/micro-core/src/main/java/com/oath/micro/server/module/Module.java @@ -1,18 +1,15 @@ -package com.aol.micro.server.module; - -import com.aol.micro.server.Plugin; -import com.aol.micro.server.PluginLoader; -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.auto.discovery.RestResource; -import com.aol.micro.server.config.Classes; -import com.aol.micro.server.servers.model.ServerData; +package com.oath.micro.server.module; + +import com.oath.micro.server.Plugin; +import com.oath.micro.server.PluginLoader; +import com.oath.micro.server.auto.discovery.Rest; +import com.oath.micro.server.auto.discovery.RestResource; +import com.oath.micro.server.config.Classes; +import com.oath.micro.server.servers.model.ServerData; import cyclops.collections.mutable.MapX; import cyclops.companion.Streams; import cyclops.collections.mutable.ListX; import cyclops.collections.mutable.SetX; -import cyclops.collections.immutable.PersistentMapX; -import cyclops.collections.immutable.PersistentSetX; -import cyclops.collections.immutable.LinkedListX; import cyclops.reactive.ReactiveSeq; import org.springframework.util.StringUtils; import org.springframework.web.context.ContextLoaderListener; @@ -169,8 +166,8 @@ default String getProviders() { .join(","); if (StringUtils.isEmpty(additional)) - return "com.aol.micro.server.rest.providers"; - return "com.aol.micro.server.rest.providers," + additional; + return "com.oath.micro.server.rest.providers"; + return "com.oath.micro.server.rest.providers," + additional; } public String getContext(); diff --git a/micro-core/src/main/java/com/aol/micro/server/module/ModuleBean.java b/micro-core/src/main/java/com/oath/micro/server/module/ModuleBean.java similarity index 77% rename from micro-core/src/main/java/com/aol/micro/server/module/ModuleBean.java rename to micro-core/src/main/java/com/oath/micro/server/module/ModuleBean.java index 0bee52227..09d5ffd0b 100644 --- a/micro-core/src/main/java/com/aol/micro/server/module/ModuleBean.java +++ b/micro-core/src/main/java/com/oath/micro/server/module/ModuleBean.java @@ -1,8 +1,4 @@ -package com.aol.micro.server.module; - -import java.util.Map; - -import javax.servlet.Filter; +package com.oath.micro.server.module; import lombok.Getter; import lombok.Builder; diff --git a/micro-core/src/main/java/com/aol/micro/server/module/ModuleDataExtractor.java b/micro-core/src/main/java/com/oath/micro/server/module/ModuleDataExtractor.java similarity index 84% rename from micro-core/src/main/java/com/aol/micro/server/module/ModuleDataExtractor.java rename to micro-core/src/main/java/com/oath/micro/server/module/ModuleDataExtractor.java index 34d322994..4946f8d5c 100644 --- a/micro-core/src/main/java/com/aol/micro/server/module/ModuleDataExtractor.java +++ b/micro-core/src/main/java/com/oath/micro/server/module/ModuleDataExtractor.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.module; +package com.oath.micro.server.module; import java.util.ArrayList; import java.util.List; @@ -13,11 +13,11 @@ import org.springframework.web.filter.DelegatingFilterProxy; -import com.aol.micro.server.auto.discovery.JaxRsResource; -import com.aol.micro.server.auto.discovery.JaxRsResourceWrapper; -import com.aol.micro.server.servers.model.FilterData; -import com.aol.micro.server.servers.model.ServerData; -import com.aol.micro.server.servers.model.ServletData; +import com.oath.micro.server.auto.discovery.JaxRsResource; +import com.oath.micro.server.auto.discovery.JaxRsResourceWrapper; +import com.oath.micro.server.servers.model.FilterData; +import com.oath.micro.server.servers.model.ServerData; +import com.oath.micro.server.servers.model.ServletData; import lombok.AllArgsConstructor; diff --git a/micro-core/src/main/java/com/aol/micro/server/module/RestResourceTagBuilder.java b/micro-core/src/main/java/com/oath/micro/server/module/RestResourceTagBuilder.java similarity index 87% rename from micro-core/src/main/java/com/aol/micro/server/module/RestResourceTagBuilder.java rename to micro-core/src/main/java/com/oath/micro/server/module/RestResourceTagBuilder.java index e7a8ee00c..a02fbfc93 100644 --- a/micro-core/src/main/java/com/aol/micro/server/module/RestResourceTagBuilder.java +++ b/micro-core/src/main/java/com/oath/micro/server/module/RestResourceTagBuilder.java @@ -1,6 +1,6 @@ -package com.aol.micro.server.module; +package com.oath.micro.server.module; -import static com.aol.micro.server.utility.UsefulStaticMethods.concat; +import static com.oath.micro.server.utility.UsefulStaticMethods.concat; import java.lang.annotation.Annotation; import java.util.List; @@ -8,13 +8,12 @@ import java.util.stream.Stream; import com.oath.cyclops.util.ExceptionSoftener; -import cyclops.collections.immutable.PersistentSetX; import cyclops.collections.mutable.SetX; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.aol.micro.server.auto.discovery.CommonRestResource; +import com.oath.micro.server.auto.discovery.CommonRestResource; import lombok.Setter; diff --git a/micro-core/src/main/java/com/aol/micro/server/module/WebServerProvider.java b/micro-core/src/main/java/com/oath/micro/server/module/WebServerProvider.java similarity index 83% rename from micro-core/src/main/java/com/aol/micro/server/module/WebServerProvider.java rename to micro-core/src/main/java/com/oath/micro/server/module/WebServerProvider.java index 08f26d08f..89ca81d69 100644 --- a/micro-core/src/main/java/com/aol/micro/server/module/WebServerProvider.java +++ b/micro-core/src/main/java/com/oath/micro/server/module/WebServerProvider.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.module; +package com.oath.micro.server.module; import lombok.AllArgsConstructor; diff --git a/micro-core/src/main/java/com/aol/micro/server/rest/RestConfiguration.java b/micro-core/src/main/java/com/oath/micro/server/rest/RestConfiguration.java similarity index 94% rename from micro-core/src/main/java/com/aol/micro/server/rest/RestConfiguration.java rename to micro-core/src/main/java/com/oath/micro/server/rest/RestConfiguration.java index 141baedf9..708f5c181 100644 --- a/micro-core/src/main/java/com/aol/micro/server/rest/RestConfiguration.java +++ b/micro-core/src/main/java/com/oath/micro/server/rest/RestConfiguration.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.rest; +package com.oath.micro.server.rest; import java.util.Map; diff --git a/micro-core/src/main/java/com/aol/micro/server/servers/AccessLogConfig.java b/micro-core/src/main/java/com/oath/micro/server/servers/AccessLogConfig.java similarity index 91% rename from micro-core/src/main/java/com/aol/micro/server/servers/AccessLogConfig.java rename to micro-core/src/main/java/com/oath/micro/server/servers/AccessLogConfig.java index 4c7c4550d..4df9cabe1 100644 --- a/micro-core/src/main/java/com/aol/micro/server/servers/AccessLogConfig.java +++ b/micro-core/src/main/java/com/oath/micro/server/servers/AccessLogConfig.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.servers; +package com.oath.micro.server.servers; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; diff --git a/micro-core/src/main/java/com/aol/micro/server/servers/AccessLogLocationBean.java b/micro-core/src/main/java/com/oath/micro/server/servers/AccessLogLocationBean.java similarity index 85% rename from micro-core/src/main/java/com/aol/micro/server/servers/AccessLogLocationBean.java rename to micro-core/src/main/java/com/oath/micro/server/servers/AccessLogLocationBean.java index 1e106713a..d00697ebd 100644 --- a/micro-core/src/main/java/com/aol/micro/server/servers/AccessLogLocationBean.java +++ b/micro-core/src/main/java/com/oath/micro/server/servers/AccessLogLocationBean.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.servers; +package com.oath.micro.server.servers; import lombok.Getter; diff --git a/micro-core/src/main/java/com/oath/micro/server/servers/ApplicationRegister.java b/micro-core/src/main/java/com/oath/micro/server/servers/ApplicationRegister.java new file mode 100644 index 000000000..1da9bcc66 --- /dev/null +++ b/micro-core/src/main/java/com/oath/micro/server/servers/ApplicationRegister.java @@ -0,0 +1,9 @@ +package com.oath.micro.server.servers; + +import com.oath.micro.server.servers.model.ServerData; + +public interface ApplicationRegister { + + void register(ServerData[] array); + +} diff --git a/micro-core/src/main/java/com/aol/micro/server/servers/FilterConfigurer.java b/micro-core/src/main/java/com/oath/micro/server/servers/FilterConfigurer.java similarity index 91% rename from micro-core/src/main/java/com/aol/micro/server/servers/FilterConfigurer.java rename to micro-core/src/main/java/com/oath/micro/server/servers/FilterConfigurer.java index ede817abc..50e6ae880 100644 --- a/micro-core/src/main/java/com/aol/micro/server/servers/FilterConfigurer.java +++ b/micro-core/src/main/java/com/oath/micro/server/servers/FilterConfigurer.java @@ -1,9 +1,8 @@ -package com.aol.micro.server.servers; +package com.oath.micro.server.servers; import java.util.EnumSet; import javax.servlet.DispatcherType; -import javax.servlet.Filter; import javax.servlet.FilterRegistration.Dynamic; import javax.servlet.ServletContext; @@ -14,9 +13,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.aol.micro.server.auto.discovery.FilterConfiguration; -import com.aol.micro.server.servers.model.FilterData; -import com.aol.micro.server.servers.model.ServerData; +import com.oath.micro.server.auto.discovery.FilterConfiguration; +import com.oath.micro.server.servers.model.FilterData; +import com.oath.micro.server.servers.model.ServerData; @AllArgsConstructor public class FilterConfigurer { diff --git a/micro-core/src/main/java/com/aol/micro/server/servers/JaxRsServletConfigurer.java b/micro-core/src/main/java/com/oath/micro/server/servers/JaxRsServletConfigurer.java similarity index 89% rename from micro-core/src/main/java/com/aol/micro/server/servers/JaxRsServletConfigurer.java rename to micro-core/src/main/java/com/oath/micro/server/servers/JaxRsServletConfigurer.java index 1040c76b2..acaffe3ce 100644 --- a/micro-core/src/main/java/com/aol/micro/server/servers/JaxRsServletConfigurer.java +++ b/micro-core/src/main/java/com/oath/micro/server/servers/JaxRsServletConfigurer.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.servers; +package com.oath.micro.server.servers; import java.util.List; import java.util.Map; @@ -6,11 +6,11 @@ import javax.servlet.ServletContext; -import com.aol.micro.server.Plugin; -import com.aol.micro.server.PluginLoader; -import com.aol.micro.server.module.IncorrectJaxRsPluginsException; -import com.aol.micro.server.rest.RestConfiguration; -import com.aol.micro.server.servers.model.ServerData; +import com.oath.micro.server.Plugin; +import com.oath.micro.server.PluginLoader; +import com.oath.micro.server.module.IncorrectJaxRsPluginsException; +import com.oath.micro.server.rest.RestConfiguration; +import com.oath.micro.server.servers.model.ServerData; import cyclops.companion.Streams; import cyclops.reactive.ReactiveSeq; diff --git a/micro-core/src/main/java/com/oath/micro/server/servers/ServerApplication.java b/micro-core/src/main/java/com/oath/micro/server/servers/ServerApplication.java new file mode 100644 index 000000000..4375c7651 --- /dev/null +++ b/micro-core/src/main/java/com/oath/micro/server/servers/ServerApplication.java @@ -0,0 +1,10 @@ +package com.oath.micro.server.servers; + +import java.util.concurrent.CompletableFuture; + +import com.oath.micro.server.servers.model.ServerData; + +public interface ServerApplication { + void run(CompletableFuture start, JaxRsServletConfigurer jaxRsConfigurer, CompletableFuture end); + ServerData getServerData(); +} diff --git a/micro-core/src/main/java/com/oath/micro/server/servers/ServerApplicationFactory.java b/micro-core/src/main/java/com/oath/micro/server/servers/ServerApplicationFactory.java new file mode 100644 index 000000000..08dd26a4a --- /dev/null +++ b/micro-core/src/main/java/com/oath/micro/server/servers/ServerApplicationFactory.java @@ -0,0 +1,10 @@ +package com.oath.micro.server.servers; + +import org.springframework.context.ApplicationContext; + +import com.oath.micro.server.module.Module; + +public interface ServerApplicationFactory { + + public ServerApplication createApp(Module module,ApplicationContext springContext); +} diff --git a/micro-core/src/main/java/com/aol/micro/server/servers/ServerRunner.java b/micro-core/src/main/java/com/oath/micro/server/servers/ServerRunner.java similarity index 94% rename from micro-core/src/main/java/com/aol/micro/server/servers/ServerRunner.java rename to micro-core/src/main/java/com/oath/micro/server/servers/ServerRunner.java index 503af9372..4d0a19f83 100644 --- a/micro-core/src/main/java/com/aol/micro/server/servers/ServerRunner.java +++ b/micro-core/src/main/java/com/oath/micro/server/servers/ServerRunner.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.servers; +package com.oath.micro.server.servers; import java.util.HashMap; import java.util.List; @@ -16,8 +16,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.aol.micro.server.module.Module; -import com.aol.micro.server.servers.model.ServerData; +import com.oath.micro.server.module.Module; +import com.oath.micro.server.servers.model.ServerData; public class ServerRunner { private final Logger logger = LoggerFactory.getLogger(getClass()); diff --git a/micro-core/src/main/java/com/aol/micro/server/servers/ServerThreadLocalVariables.java b/micro-core/src/main/java/com/oath/micro/server/servers/ServerThreadLocalVariables.java similarity index 80% rename from micro-core/src/main/java/com/aol/micro/server/servers/ServerThreadLocalVariables.java rename to micro-core/src/main/java/com/oath/micro/server/servers/ServerThreadLocalVariables.java index 8eaacd8c8..e1ed67f34 100644 --- a/micro-core/src/main/java/com/aol/micro/server/servers/ServerThreadLocalVariables.java +++ b/micro-core/src/main/java/com/oath/micro/server/servers/ServerThreadLocalVariables.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.servers; +package com.oath.micro.server.servers; import lombok.Getter; diff --git a/micro-core/src/main/java/com/aol/micro/server/servers/ServletConfigurer.java b/micro-core/src/main/java/com/oath/micro/server/servers/ServletConfigurer.java similarity index 91% rename from micro-core/src/main/java/com/aol/micro/server/servers/ServletConfigurer.java rename to micro-core/src/main/java/com/oath/micro/server/servers/ServletConfigurer.java index 28b366c57..1617791a5 100644 --- a/micro-core/src/main/java/com/aol/micro/server/servers/ServletConfigurer.java +++ b/micro-core/src/main/java/com/oath/micro/server/servers/ServletConfigurer.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.servers; +package com.oath.micro.server.servers; import javax.servlet.ServletContext; import javax.servlet.ServletRegistration; @@ -7,9 +7,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.aol.micro.server.auto.discovery.ServletConfiguration; -import com.aol.micro.server.servers.model.ServerData; -import com.aol.micro.server.servers.model.ServletData; +import com.oath.micro.server.auto.discovery.ServletConfiguration; +import com.oath.micro.server.servers.model.ServerData; +import com.oath.micro.server.servers.model.ServletData; import lombok.AllArgsConstructor; diff --git a/micro-core/src/main/java/com/aol/micro/server/servers/ServletContextListenerConfigurer.java b/micro-core/src/main/java/com/oath/micro/server/servers/ServletContextListenerConfigurer.java similarity index 95% rename from micro-core/src/main/java/com/aol/micro/server/servers/ServletContextListenerConfigurer.java rename to micro-core/src/main/java/com/oath/micro/server/servers/ServletContextListenerConfigurer.java index 44e879439..63389299c 100644 --- a/micro-core/src/main/java/com/aol/micro/server/servers/ServletContextListenerConfigurer.java +++ b/micro-core/src/main/java/com/oath/micro/server/servers/ServletContextListenerConfigurer.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.servers; +package com.oath.micro.server.servers; import java.util.List; @@ -13,7 +13,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.aol.micro.server.servers.model.ServerData; +import com.oath.micro.server.servers.model.ServerData; @AllArgsConstructor public class ServletContextListenerConfigurer { diff --git a/micro-core/src/main/java/com/aol/micro/server/servers/model/AllData.java b/micro-core/src/main/java/com/oath/micro/server/servers/model/AllData.java similarity index 95% rename from micro-core/src/main/java/com/aol/micro/server/servers/model/AllData.java rename to micro-core/src/main/java/com/oath/micro/server/servers/model/AllData.java index 433682275..bec23c964 100644 --- a/micro-core/src/main/java/com/aol/micro/server/servers/model/AllData.java +++ b/micro-core/src/main/java/com/oath/micro/server/servers/model/AllData.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.servers.model; +package com.oath.micro.server.servers.model; import java.util.ArrayList; import java.util.List; @@ -12,7 +12,7 @@ import lombok.Builder; -import com.aol.micro.server.utility.UsefulStaticMethods; +import com.oath.micro.server.utility.UsefulStaticMethods; @Getter @Builder diff --git a/micro-core/src/main/java/com/aol/micro/server/servers/model/FilterData.java b/micro-core/src/main/java/com/oath/micro/server/servers/model/FilterData.java similarity index 88% rename from micro-core/src/main/java/com/aol/micro/server/servers/model/FilterData.java rename to micro-core/src/main/java/com/oath/micro/server/servers/model/FilterData.java index 5d93d689f..a7c0bd48a 100644 --- a/micro-core/src/main/java/com/aol/micro/server/servers/model/FilterData.java +++ b/micro-core/src/main/java/com/oath/micro/server/servers/model/FilterData.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.servers.model; +package com.oath.micro.server.servers.model; import javax.servlet.Filter; diff --git a/micro-core/src/main/java/com/aol/micro/server/servers/model/RestResourceMissingPathException.java b/micro-core/src/main/java/com/oath/micro/server/servers/model/RestResourceMissingPathException.java similarity index 82% rename from micro-core/src/main/java/com/aol/micro/server/servers/model/RestResourceMissingPathException.java rename to micro-core/src/main/java/com/oath/micro/server/servers/model/RestResourceMissingPathException.java index d68f2c4ec..218b13d6d 100644 --- a/micro-core/src/main/java/com/aol/micro/server/servers/model/RestResourceMissingPathException.java +++ b/micro-core/src/main/java/com/oath/micro/server/servers/model/RestResourceMissingPathException.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.servers.model; +package com.oath.micro.server.servers.model; public class RestResourceMissingPathException extends RuntimeException { diff --git a/micro-core/src/main/java/com/aol/micro/server/servers/model/ServerData.java b/micro-core/src/main/java/com/oath/micro/server/servers/model/ServerData.java similarity index 94% rename from micro-core/src/main/java/com/aol/micro/server/servers/model/ServerData.java rename to micro-core/src/main/java/com/oath/micro/server/servers/model/ServerData.java index 470ac40db..9d4db3da4 100644 --- a/micro-core/src/main/java/com/aol/micro/server/servers/model/ServerData.java +++ b/micro-core/src/main/java/com/oath/micro/server/servers/model/ServerData.java @@ -1,7 +1,6 @@ -package com.aol.micro.server.servers.model; +package com.oath.micro.server.servers.model; import java.util.List; -import java.util.stream.Collectors; import javax.ws.rs.Path; @@ -18,7 +17,7 @@ import org.slf4j.LoggerFactory; import org.springframework.context.ApplicationContext; -import com.aol.micro.server.module.Module; +import com.oath.micro.server.module.Module; @Getter @Builder diff --git a/micro-core/src/main/java/com/aol/micro/server/servers/model/ServletData.java b/micro-core/src/main/java/com/oath/micro/server/servers/model/ServletData.java similarity index 85% rename from micro-core/src/main/java/com/aol/micro/server/servers/model/ServletData.java rename to micro-core/src/main/java/com/oath/micro/server/servers/model/ServletData.java index e784c1730..b44a415ea 100644 --- a/micro-core/src/main/java/com/aol/micro/server/servers/model/ServletData.java +++ b/micro-core/src/main/java/com/oath/micro/server/servers/model/ServletData.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.servers.model; +package com.oath.micro.server.servers.model; import javax.servlet.Servlet; diff --git a/micro-core/src/main/java/com/aol/micro/server/spring/SpringApplicationConfigurator.java b/micro-core/src/main/java/com/oath/micro/server/spring/SpringApplicationConfigurator.java similarity index 92% rename from micro-core/src/main/java/com/aol/micro/server/spring/SpringApplicationConfigurator.java rename to micro-core/src/main/java/com/oath/micro/server/spring/SpringApplicationConfigurator.java index fdb7fe220..3c834b177 100644 --- a/micro-core/src/main/java/com/aol/micro/server/spring/SpringApplicationConfigurator.java +++ b/micro-core/src/main/java/com/oath/micro/server/spring/SpringApplicationConfigurator.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.spring; +package com.oath.micro.server.spring; import java.util.List; @@ -10,10 +10,10 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; -import com.aol.micro.server.Plugin; -import com.aol.micro.server.PluginLoader; -import com.aol.micro.server.config.Config; -import com.aol.micro.server.config.ConfigAccessor; +import com.oath.micro.server.Plugin; +import com.oath.micro.server.PluginLoader; +import com.oath.micro.server.config.Config; +import com.oath.micro.server.config.ConfigAccessor; public class SpringApplicationConfigurator implements SpringBuilder { private final Logger logger = LoggerFactory.getLogger(this.getClass()); diff --git a/micro-core/src/main/java/com/oath/micro/server/spring/SpringBuilder.java b/micro-core/src/main/java/com/oath/micro/server/spring/SpringBuilder.java new file mode 100644 index 000000000..090fbe359 --- /dev/null +++ b/micro-core/src/main/java/com/oath/micro/server/spring/SpringBuilder.java @@ -0,0 +1,9 @@ +package com.oath.micro.server.spring; + +import org.springframework.context.ConfigurableApplicationContext; + +import com.oath.micro.server.config.Config; + +public interface SpringBuilder { + public ConfigurableApplicationContext createSpringApp(Config config, Class...classes); +} diff --git a/micro-core/src/main/java/com/aol/micro/server/spring/SpringContextFactory.java b/micro-core/src/main/java/com/oath/micro/server/spring/SpringContextFactory.java similarity index 93% rename from micro-core/src/main/java/com/aol/micro/server/spring/SpringContextFactory.java rename to micro-core/src/main/java/com/oath/micro/server/spring/SpringContextFactory.java index e23eb50b8..f9596d269 100644 --- a/micro-core/src/main/java/com/aol/micro/server/spring/SpringContextFactory.java +++ b/micro-core/src/main/java/com/oath/micro/server/spring/SpringContextFactory.java @@ -1,7 +1,6 @@ -package com.aol.micro.server.spring; +package com.oath.micro.server.spring; import java.util.Arrays; -import java.util.HashSet; import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; @@ -15,11 +14,11 @@ import org.springframework.context.ApplicationContext; -import com.aol.micro.server.InternalErrorCode; -import com.aol.micro.server.Plugin; -import com.aol.micro.server.PluginLoader; -import com.aol.micro.server.config.Config; -import com.aol.micro.server.config.Microserver; +import com.oath.micro.server.InternalErrorCode; +import com.oath.micro.server.Plugin; +import com.oath.micro.server.PluginLoader; +import com.oath.micro.server.config.Config; +import com.oath.micro.server.config.Microserver; import lombok.AllArgsConstructor; import lombok.experimental.Wither; diff --git a/micro-core/src/main/java/com/aol/micro/server/spring/SpringDBConfig.java b/micro-core/src/main/java/com/oath/micro/server/spring/SpringDBConfig.java similarity index 84% rename from micro-core/src/main/java/com/aol/micro/server/spring/SpringDBConfig.java rename to micro-core/src/main/java/com/oath/micro/server/spring/SpringDBConfig.java index 03260134a..399da4815 100644 --- a/micro-core/src/main/java/com/aol/micro/server/spring/SpringDBConfig.java +++ b/micro-core/src/main/java/com/oath/micro/server/spring/SpringDBConfig.java @@ -1,9 +1,9 @@ -package com.aol.micro.server.spring; +package com.oath.micro.server.spring; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; -import com.aol.micro.server.config.Config; +import com.oath.micro.server.config.Config; public interface SpringDBConfig { diff --git a/micro-core/src/main/java/com/aol/micro/server/spring/properties/PropertyFileConfig.java b/micro-core/src/main/java/com/oath/micro/server/spring/properties/PropertyFileConfig.java similarity index 96% rename from micro-core/src/main/java/com/aol/micro/server/spring/properties/PropertyFileConfig.java rename to micro-core/src/main/java/com/oath/micro/server/spring/properties/PropertyFileConfig.java index 1a28ebaaf..a261bb354 100644 --- a/micro-core/src/main/java/com/aol/micro/server/spring/properties/PropertyFileConfig.java +++ b/micro-core/src/main/java/com/oath/micro/server/spring/properties/PropertyFileConfig.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.spring.properties; +package com.oath.micro.server.spring.properties; import java.io.File; import java.io.IOException; @@ -8,7 +8,6 @@ import java.util.Optional; import java.util.Properties; -import cyclops.data.tuple.Tuple2; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.config.PropertiesFactoryBean; @@ -19,8 +18,8 @@ import org.springframework.core.io.Resource; import org.springframework.core.io.UrlResource; -import com.aol.micro.server.config.Config; -import com.aol.micro.server.config.ConfigAccessor; +import com.oath.micro.server.config.Config; +import com.oath.micro.server.config.ConfigAccessor; @Configuration public class PropertyFileConfig { diff --git a/micro-core/src/main/java/com/aol/micro/server/utility/HashMapBuilder.java b/micro-core/src/main/java/com/oath/micro/server/utility/HashMapBuilder.java similarity index 98% rename from micro-core/src/main/java/com/aol/micro/server/utility/HashMapBuilder.java rename to micro-core/src/main/java/com/oath/micro/server/utility/HashMapBuilder.java index 9c5314638..3b3714ec5 100644 --- a/micro-core/src/main/java/com/aol/micro/server/utility/HashMapBuilder.java +++ b/micro-core/src/main/java/com/oath/micro/server/utility/HashMapBuilder.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.utility; +package com.oath.micro.server.utility; import java.util.Collections; import java.util.HashMap; diff --git a/micro-core/src/main/java/com/aol/micro/server/utility/UsefulStaticMethods.java b/micro-core/src/main/java/com/oath/micro/server/utility/UsefulStaticMethods.java similarity index 93% rename from micro-core/src/main/java/com/aol/micro/server/utility/UsefulStaticMethods.java rename to micro-core/src/main/java/com/oath/micro/server/utility/UsefulStaticMethods.java index 2b29cdc80..f05837716 100644 --- a/micro-core/src/main/java/com/aol/micro/server/utility/UsefulStaticMethods.java +++ b/micro-core/src/main/java/com/oath/micro/server/utility/UsefulStaticMethods.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.utility; +package com.oath.micro.server.utility; import static java.util.Optional.ofNullable; diff --git a/micro-core/src/main/java/nonautoscan/com/aol/micro/server/AopConfig.java b/micro-core/src/main/java/nonautoscan/com/oath/micro/server/AopConfig.java similarity index 83% rename from micro-core/src/main/java/nonautoscan/com/aol/micro/server/AopConfig.java rename to micro-core/src/main/java/nonautoscan/com/oath/micro/server/AopConfig.java index e24028faa..f80f6d643 100644 --- a/micro-core/src/main/java/nonautoscan/com/aol/micro/server/AopConfig.java +++ b/micro-core/src/main/java/nonautoscan/com/oath/micro/server/AopConfig.java @@ -1,4 +1,4 @@ -package nonautoscan.com.aol.micro.server; +package nonautoscan.com.oath.micro.server; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.EnableAspectJAutoProxy; diff --git a/micro-core/src/main/java/nonautoscan/com/aol/micro/server/SSLConfig.java b/micro-core/src/main/java/nonautoscan/com/oath/micro/server/SSLConfig.java similarity index 95% rename from micro-core/src/main/java/nonautoscan/com/aol/micro/server/SSLConfig.java rename to micro-core/src/main/java/nonautoscan/com/oath/micro/server/SSLConfig.java index 3c09f045c..045cc530f 100644 --- a/micro-core/src/main/java/nonautoscan/com/aol/micro/server/SSLConfig.java +++ b/micro-core/src/main/java/nonautoscan/com/oath/micro/server/SSLConfig.java @@ -1,4 +1,4 @@ -package nonautoscan.com.aol.micro.server; +package nonautoscan.com.oath.micro.server; import java.io.IOException; import java.net.URL; @@ -10,7 +10,7 @@ import org.springframework.core.io.Resource; import org.springframework.core.io.UrlResource; -import com.aol.micro.server.config.SSLProperties; +import com.oath.micro.server.config.SSLProperties; @Configuration public class SSLConfig { diff --git a/micro-core/src/main/java/nonautoscan/com/aol/micro/server/ScheduleAndAsyncConfig.java b/micro-core/src/main/java/nonautoscan/com/oath/micro/server/ScheduleAndAsyncConfig.java similarity index 94% rename from micro-core/src/main/java/nonautoscan/com/aol/micro/server/ScheduleAndAsyncConfig.java rename to micro-core/src/main/java/nonautoscan/com/oath/micro/server/ScheduleAndAsyncConfig.java index 28a08a2f1..08e9cdc0e 100644 --- a/micro-core/src/main/java/nonautoscan/com/aol/micro/server/ScheduleAndAsyncConfig.java +++ b/micro-core/src/main/java/nonautoscan/com/oath/micro/server/ScheduleAndAsyncConfig.java @@ -1,4 +1,4 @@ -package nonautoscan.com.aol.micro.server; +package nonautoscan.com.oath.micro.server; import java.util.concurrent.Executor; import java.util.concurrent.Executors; @@ -11,7 +11,7 @@ import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.config.ScheduledTaskRegistrar; -import com.aol.micro.server.SchedulingConfiguration; +import com.oath.micro.server.SchedulingConfiguration; @Configuration @EnableScheduling diff --git a/micro-core/src/test/java/com/aol/micro/server/config/SimpleApp.java b/micro-core/src/test/java/com/aol/micro/server/config/SimpleApp.java deleted file mode 100644 index ea0e36ebc..000000000 --- a/micro-core/src/test/java/com/aol/micro/server/config/SimpleApp.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.aol.micro.server.config; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.Rest; - -@Microserver -@Rest -@Path("/test") -public class SimpleApp { - - public static void main(String[] args){ - new MicroserverApp(()->"hello-world").run(); - } - - @GET - public String test(){ - return "ok!"; - } -} diff --git a/micro-core/src/test/java/com/aol/micro/server/model/ServletStatusResource.java b/micro-core/src/test/java/com/aol/micro/server/model/ServletStatusResource.java deleted file mode 100644 index 7eed4bcb7..000000000 --- a/micro-core/src/test/java/com/aol/micro/server/model/ServletStatusResource.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.aol.micro.server.model; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.RestResource; - -@Component -@Path("/servlet") -public class ServletStatusResource implements RestResource { - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "ok"; - } - -} \ No newline at end of file diff --git a/micro-core/src/test/java/com/aol/micro/server/module/HttpServer.java b/micro-core/src/test/java/com/aol/micro/server/module/HttpServer.java deleted file mode 100644 index b3eebc077..000000000 --- a/micro-core/src/test/java/com/aol/micro/server/module/HttpServer.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.aol.micro.server.module; - -public class HttpServer { - -} diff --git a/micro-core/src/test/java/com/aol/micro/server/module/MyPlugin.java b/micro-core/src/test/java/com/aol/micro/server/module/MyPlugin.java deleted file mode 100644 index ef1efaa1a..000000000 --- a/micro-core/src/test/java/com/aol/micro/server/module/MyPlugin.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.aol.micro.server.module; - - -import com.aol.micro.server.Plugin; -import cyclops.collections.immutable.LinkedListX; -import cyclops.collections.mutable.ListX; - -import java.util.List; - -public class MyPlugin implements Plugin{ - public List providers(){ - return ListX.of("com.my.new.provider","com.my.new.provider2"); - } -} \ No newline at end of file diff --git a/micro-core/src/test/java/com/aol/micro/server/module/RestResourceTagBuilderTest.java b/micro-core/src/test/java/com/aol/micro/server/module/RestResourceTagBuilderTest.java deleted file mode 100644 index db4622aa8..000000000 --- a/micro-core/src/test/java/com/aol/micro/server/module/RestResourceTagBuilderTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.aol.micro.server.module; - -import static org.hamcrest.Matchers.hasItem; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; - -import org.junit.Test; - -import com.aol.micro.server.auto.discovery.CommonRestResource; -public class RestResourceTagBuilderTest { - - @Test(expected=ClassNotFoundException.class) - public void testRestResourceTagNonsense() { - RestResourceTagBuilder.restResourceTags("com.aol.micro.server.module.RestResourceTagBuilderTest","nonsense"); - fail("should not get here, ClassNotFound expected"); - } - @Test - public void testRestResourceTag() { - assertThat(RestResourceTagBuilder.restResourceTags("com.aol.micro.server.module.RestResourceTagBuilderTest"), hasItem( RestResourceTagBuilderTest.class)); - } - @Test - public void testRestResourceTagClasses() { - assertThat(RestResourceTagBuilder.restResourceTags(RestResourceTagBuilderTest.class), hasItem( RestResourceTagBuilderTest.class)); - } - @Test - public void testRestResourceTagDefaults() { - assertThat(RestResourceTagBuilder.restResourceTags("com.aol.micro.server.module.RestResourceTagBuilderTest"), hasItem( CommonRestResource.class)); - } - @Test - public void testRestResourceTagClassesDefaults() { - assertThat(RestResourceTagBuilder.restResourceTags(RestResourceTagBuilderTest.class), hasItem( CommonRestResource.class)); - } - - -} diff --git a/micro-core/src/test/java/com/aol/micro/server/simpleserver/HelloResource.java b/micro-core/src/test/java/com/aol/micro/server/simpleserver/HelloResource.java deleted file mode 100644 index cd934e10d..000000000 --- a/micro-core/src/test/java/com/aol/micro/server/simpleserver/HelloResource.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.aol.micro.server.simpleserver; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import com.aol.micro.server.auto.discovery.Rest; - -@Rest -@Path("/foo") -public class HelloResource { - - @GET - @Produces("text/plain") - @Path("/hello") - public String hello() { - return "world"; - } -} \ No newline at end of file diff --git a/micro-core/src/test/java/com/aol/micro/server/simpleserver/TestMicroserverApp.java b/micro-core/src/test/java/com/aol/micro/server/simpleserver/TestMicroserverApp.java deleted file mode 100644 index 00bc032ad..000000000 --- a/micro-core/src/test/java/com/aol/micro/server/simpleserver/TestMicroserverApp.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.aol.micro.server.simpleserver; - - -import com.aol.micro.server.MicroserverApp; - -public class TestMicroserverApp { - - public static void main(String[] args) { - // SLF4JBridgeHandler.removeHandlersForRootLogger(); - // SLF4JBridgeHandler.install(); - - new MicroserverApp(()->"simple").start(); - } - -} \ No newline at end of file diff --git a/micro-core/src/test/java/com/aol/micro/server/utility/UsefulStaticMethodsTest.java b/micro-core/src/test/java/com/aol/micro/server/utility/UsefulStaticMethodsTest.java deleted file mode 100644 index 7e9b0e7a3..000000000 --- a/micro-core/src/test/java/com/aol/micro/server/utility/UsefulStaticMethodsTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.aol.micro.server.utility; - -import static com.aol.micro.server.utility.UsefulStaticMethods.either; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.*; - -import org.junit.Test; - -public class UsefulStaticMethodsTest { - - @Test - public void testEither() { - assertThat(either(null, "answer"), is("answer")); - assertThat(either("answer", "different"), is("answer")); - } - -} diff --git a/micro-core/src/test/java/com/aol/micro/server/config/MicroserverConfigurerTest.java b/micro-core/src/test/java/com/oath/micro/server/config/MicroserverConfigurerTest.java similarity index 98% rename from micro-core/src/test/java/com/aol/micro/server/config/MicroserverConfigurerTest.java rename to micro-core/src/test/java/com/oath/micro/server/config/MicroserverConfigurerTest.java index af11e1086..a7d7b5919 100644 --- a/micro-core/src/test/java/com/aol/micro/server/config/MicroserverConfigurerTest.java +++ b/micro-core/src/test/java/com/oath/micro/server/config/MicroserverConfigurerTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.config; +package com.oath.micro.server.config; import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.equalTo; diff --git a/micro-core/src/test/java/com/oath/micro/server/config/SimpleApp.java b/micro-core/src/test/java/com/oath/micro/server/config/SimpleApp.java new file mode 100644 index 000000000..eaa971e39 --- /dev/null +++ b/micro-core/src/test/java/com/oath/micro/server/config/SimpleApp.java @@ -0,0 +1,22 @@ +package com.oath.micro.server.config; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.auto.discovery.Rest; + +@Microserver +@Rest +@Path("/test") +public class SimpleApp { + + public static void main(String[] args){ + new MicroserverApp(()->"hello-world").run(); + } + + @GET + public String test(){ + return "ok!"; + } +} diff --git a/micro-core/src/test/java/com/aol/micro/server/model/FilterDataTest.java b/micro-core/src/test/java/com/oath/micro/server/model/FilterDataTest.java similarity index 84% rename from micro-core/src/test/java/com/aol/micro/server/model/FilterDataTest.java rename to micro-core/src/test/java/com/oath/micro/server/model/FilterDataTest.java index 241dc6555..6ef0b74af 100644 --- a/micro-core/src/test/java/com/aol/micro/server/model/FilterDataTest.java +++ b/micro-core/src/test/java/com/oath/micro/server/model/FilterDataTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.model; +package com.oath.micro.server.model; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; @@ -8,7 +8,7 @@ import org.junit.Test; -import com.aol.micro.server.servers.model.FilterData; +import com.oath.micro.server.servers.model.FilterData; public class FilterDataTest { diff --git a/micro-core/src/test/java/com/aol/micro/server/model/ServerDataTest.java b/micro-core/src/test/java/com/oath/micro/server/model/ServerDataTest.java similarity index 91% rename from micro-core/src/test/java/com/aol/micro/server/model/ServerDataTest.java rename to micro-core/src/test/java/com/oath/micro/server/model/ServerDataTest.java index 4baffd406..10382572f 100644 --- a/micro-core/src/test/java/com/aol/micro/server/model/ServerDataTest.java +++ b/micro-core/src/test/java/com/oath/micro/server/model/ServerDataTest.java @@ -1,13 +1,10 @@ -package com.aol.micro.server.model; +package com.oath.micro.server.model; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; import static org.mockito.Mockito.mock; import java.util.Arrays; -import java.util.stream.Collectors; - - import org.junit.Before; @@ -15,7 +12,7 @@ import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; -import com.aol.micro.server.servers.model.ServerData; +import com.oath.micro.server.servers.model.ServerData; public class ServerDataTest { diff --git a/micro-core/src/test/java/com/oath/micro/server/model/ServletStatusResource.java b/micro-core/src/test/java/com/oath/micro/server/model/ServletStatusResource.java new file mode 100644 index 000000000..17837dcfc --- /dev/null +++ b/micro-core/src/test/java/com/oath/micro/server/model/ServletStatusResource.java @@ -0,0 +1,22 @@ +package com.oath.micro.server.model; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.RestResource; + +@Component +@Path("/servlet") +public class ServletStatusResource implements RestResource { + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "ok"; + } + +} \ No newline at end of file diff --git a/micro-core/src/test/java/com/aol/micro/server/module/BasicFilter.java b/micro-core/src/test/java/com/oath/micro/server/module/BasicFilter.java similarity index 94% rename from micro-core/src/test/java/com/aol/micro/server/module/BasicFilter.java rename to micro-core/src/test/java/com/oath/micro/server/module/BasicFilter.java index a75a34231..854bd316f 100644 --- a/micro-core/src/test/java/com/aol/micro/server/module/BasicFilter.java +++ b/micro-core/src/test/java/com/oath/micro/server/module/BasicFilter.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.module; +package com.oath.micro.server.module; import java.io.IOException; diff --git a/micro-core/src/test/java/com/aol/micro/server/module/ConfigurableModuleTest.java b/micro-core/src/test/java/com/oath/micro/server/module/ConfigurableModuleTest.java similarity index 97% rename from micro-core/src/test/java/com/aol/micro/server/module/ConfigurableModuleTest.java rename to micro-core/src/test/java/com/oath/micro/server/module/ConfigurableModuleTest.java index a20fc6928..a1e88d86d 100644 --- a/micro-core/src/test/java/com/aol/micro/server/module/ConfigurableModuleTest.java +++ b/micro-core/src/test/java/com/oath/micro/server/module/ConfigurableModuleTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.module; +package com.oath.micro.server.module; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasItem; @@ -30,10 +30,10 @@ -import com.aol.micro.server.auto.discovery.CommonRestResource; -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.servers.model.ServerData; -import com.aol.micro.server.utility.HashMapBuilder; +import com.oath.micro.server.auto.discovery.CommonRestResource; +import com.oath.micro.server.auto.discovery.Rest; +import com.oath.micro.server.servers.model.ServerData; +import com.oath.micro.server.utility.HashMapBuilder; public class ConfigurableModuleTest { diff --git a/micro-core/src/test/java/com/aol/micro/server/module/ConfigureEnviromentTest.java b/micro-core/src/test/java/com/oath/micro/server/module/ConfigureEnviromentTest.java similarity index 95% rename from micro-core/src/test/java/com/aol/micro/server/module/ConfigureEnviromentTest.java rename to micro-core/src/test/java/com/oath/micro/server/module/ConfigureEnviromentTest.java index 4e390aade..638db2966 100644 --- a/micro-core/src/test/java/com/aol/micro/server/module/ConfigureEnviromentTest.java +++ b/micro-core/src/test/java/com/oath/micro/server/module/ConfigureEnviromentTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.module; +package com.oath.micro.server.module; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; diff --git a/micro-core/src/test/java/com/aol/micro/server/module/DummyQueryIPRetriever.java b/micro-core/src/test/java/com/oath/micro/server/module/DummyQueryIPRetriever.java similarity index 94% rename from micro-core/src/test/java/com/aol/micro/server/module/DummyQueryIPRetriever.java rename to micro-core/src/test/java/com/oath/micro/server/module/DummyQueryIPRetriever.java index 044b457f3..8e2ed3515 100644 --- a/micro-core/src/test/java/com/aol/micro/server/module/DummyQueryIPRetriever.java +++ b/micro-core/src/test/java/com/oath/micro/server/module/DummyQueryIPRetriever.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.module; +package com.oath.micro.server.module; import java.io.IOException; diff --git a/micro-core/src/test/java/com/aol/micro/server/module/EmbeddedModuleTest.java b/micro-core/src/test/java/com/oath/micro/server/module/EmbeddedModuleTest.java similarity index 83% rename from micro-core/src/test/java/com/aol/micro/server/module/EmbeddedModuleTest.java rename to micro-core/src/test/java/com/oath/micro/server/module/EmbeddedModuleTest.java index 640bc167a..a3810b191 100644 --- a/micro-core/src/test/java/com/aol/micro/server/module/EmbeddedModuleTest.java +++ b/micro-core/src/test/java/com/oath/micro/server/module/EmbeddedModuleTest.java @@ -1,6 +1,6 @@ -package com.aol.micro.server.module; +package com.oath.micro.server.module; -import static com.aol.micro.server.module.RestResourceTagBuilder.restAnnotations; +import static com.oath.micro.server.module.RestResourceTagBuilder.restAnnotations; import static org.hamcrest.Matchers.hasItem; import static org.junit.Assert.assertThat; diff --git a/micro-core/src/test/java/com/aol/micro/server/module/EnvironmentTest.java b/micro-core/src/test/java/com/oath/micro/server/module/EnvironmentTest.java similarity index 98% rename from micro-core/src/test/java/com/aol/micro/server/module/EnvironmentTest.java rename to micro-core/src/test/java/com/oath/micro/server/module/EnvironmentTest.java index f47ce9a2d..f675b1123 100644 --- a/micro-core/src/test/java/com/aol/micro/server/module/EnvironmentTest.java +++ b/micro-core/src/test/java/com/oath/micro/server/module/EnvironmentTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.module; +package com.oath.micro.server.module; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.not; diff --git a/micro-core/src/test/java/com/oath/micro/server/module/HttpServer.java b/micro-core/src/test/java/com/oath/micro/server/module/HttpServer.java new file mode 100644 index 000000000..256f32b03 --- /dev/null +++ b/micro-core/src/test/java/com/oath/micro/server/module/HttpServer.java @@ -0,0 +1,5 @@ +package com.oath.micro.server.module; + +public class HttpServer { + +} diff --git a/micro-core/src/test/java/com/aol/micro/server/module/ModuleDataExtractorTest.java b/micro-core/src/test/java/com/oath/micro/server/module/ModuleDataExtractorTest.java similarity index 87% rename from micro-core/src/test/java/com/aol/micro/server/module/ModuleDataExtractorTest.java rename to micro-core/src/test/java/com/oath/micro/server/module/ModuleDataExtractorTest.java index 5d89cfe11..24b225419 100644 --- a/micro-core/src/test/java/com/aol/micro/server/module/ModuleDataExtractorTest.java +++ b/micro-core/src/test/java/com/oath/micro/server/module/ModuleDataExtractorTest.java @@ -1,13 +1,12 @@ -package com.aol.micro.server.module; +package com.oath.micro.server.module; -import static com.aol.micro.server.module.RestResourceTagBuilder.restResourceTags; +import static com.oath.micro.server.module.RestResourceTagBuilder.restResourceTags; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import java.util.Arrays; import java.util.Map; import javax.servlet.Filter; @@ -19,8 +18,8 @@ import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; -import com.aol.micro.server.servers.model.ServerData; -import com.aol.micro.server.utility.HashMapBuilder; +import com.oath.micro.server.servers.model.ServerData; +import com.oath.micro.server.utility.HashMapBuilder; public class ModuleDataExtractorTest { diff --git a/micro-core/src/test/java/com/aol/micro/server/module/ModuleTest.java b/micro-core/src/test/java/com/oath/micro/server/module/ModuleTest.java similarity index 82% rename from micro-core/src/test/java/com/aol/micro/server/module/ModuleTest.java rename to micro-core/src/test/java/com/oath/micro/server/module/ModuleTest.java index 92ceec8e2..3b9080870 100644 --- a/micro-core/src/test/java/com/aol/micro/server/module/ModuleTest.java +++ b/micro-core/src/test/java/com/oath/micro/server/module/ModuleTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.module; +package com.oath.micro.server.module; import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertThat; @@ -9,13 +9,13 @@ import org.junit.Test; -import com.aol.micro.server.Plugin; +import com.oath.micro.server.Plugin; public class ModuleTest { @Test public void testProviders(){ //test MyPlugin working - assertThat("com.aol.micro.server.rest.providers,com.my.new.provider,com.my.new.provider2", + assertThat("com.oath.micro.server.rest.providers,com.my.new.provider,com.my.new.provider2", equalTo(ConfigurableModule.builder().build().getProviders())); System.out.println(new ModuleImpl().getProviders()); String additional = ReactiveSeq diff --git a/micro-core/src/test/java/com/oath/micro/server/module/MyPlugin.java b/micro-core/src/test/java/com/oath/micro/server/module/MyPlugin.java new file mode 100644 index 000000000..d1eac2356 --- /dev/null +++ b/micro-core/src/test/java/com/oath/micro/server/module/MyPlugin.java @@ -0,0 +1,13 @@ +package com.oath.micro.server.module; + + +import com.oath.micro.server.Plugin; +import cyclops.collections.mutable.ListX; + +import java.util.List; + +public class MyPlugin implements Plugin{ + public List providers(){ + return ListX.of("com.my.new.provider","com.my.new.provider2"); + } +} \ No newline at end of file diff --git a/micro-core/src/test/java/com/oath/micro/server/module/RestResourceTagBuilderTest.java b/micro-core/src/test/java/com/oath/micro/server/module/RestResourceTagBuilderTest.java new file mode 100644 index 000000000..64921a0dc --- /dev/null +++ b/micro-core/src/test/java/com/oath/micro/server/module/RestResourceTagBuilderTest.java @@ -0,0 +1,35 @@ +package com.oath.micro.server.module; + +import static org.hamcrest.Matchers.hasItem; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; + +import org.junit.Test; + +import com.oath.micro.server.auto.discovery.CommonRestResource; +public class RestResourceTagBuilderTest { + + @Test(expected=ClassNotFoundException.class) + public void testRestResourceTagNonsense() { + RestResourceTagBuilder.restResourceTags("com.oath.micro.server.module.RestResourceTagBuilderTest","nonsense"); + fail("should not get here, ClassNotFound expected"); + } + @Test + public void testRestResourceTag() { + assertThat(RestResourceTagBuilder.restResourceTags("com.oath.micro.server.module.RestResourceTagBuilderTest"), hasItem( RestResourceTagBuilderTest.class)); + } + @Test + public void testRestResourceTagClasses() { + assertThat(RestResourceTagBuilder.restResourceTags(RestResourceTagBuilderTest.class), hasItem( RestResourceTagBuilderTest.class)); + } + @Test + public void testRestResourceTagDefaults() { + assertThat(RestResourceTagBuilder.restResourceTags("com.oath.micro.server.module.RestResourceTagBuilderTest"), hasItem( CommonRestResource.class)); + } + @Test + public void testRestResourceTagClassesDefaults() { + assertThat(RestResourceTagBuilder.restResourceTags(RestResourceTagBuilderTest.class), hasItem( CommonRestResource.class)); + } + + +} diff --git a/micro-core/src/test/java/com/oath/micro/server/simpleserver/HelloResource.java b/micro-core/src/test/java/com/oath/micro/server/simpleserver/HelloResource.java new file mode 100644 index 000000000..6d3fb683f --- /dev/null +++ b/micro-core/src/test/java/com/oath/micro/server/simpleserver/HelloResource.java @@ -0,0 +1,19 @@ +package com.oath.micro.server.simpleserver; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import com.oath.micro.server.auto.discovery.Rest; + +@Rest +@Path("/foo") +public class HelloResource { + + @GET + @Produces("text/plain") + @Path("/hello") + public String hello() { + return "world"; + } +} \ No newline at end of file diff --git a/micro-core/src/test/java/com/oath/micro/server/simpleserver/TestMicroserverApp.java b/micro-core/src/test/java/com/oath/micro/server/simpleserver/TestMicroserverApp.java new file mode 100644 index 000000000..333fa6e46 --- /dev/null +++ b/micro-core/src/test/java/com/oath/micro/server/simpleserver/TestMicroserverApp.java @@ -0,0 +1,15 @@ +package com.oath.micro.server.simpleserver; + + +import com.oath.micro.server.MicroserverApp; + +public class TestMicroserverApp { + + public static void main(String[] args) { + // SLF4JBridgeHandler.removeHandlersForRootLogger(); + // SLF4JBridgeHandler.install(); + + new MicroserverApp(()->"simple").start(); + } + +} \ No newline at end of file diff --git a/micro-core/src/test/java/com/aol/micro/server/spring/SpringContextFactoryTest.java b/micro-core/src/test/java/com/oath/micro/server/spring/SpringContextFactoryTest.java similarity index 90% rename from micro-core/src/test/java/com/aol/micro/server/spring/SpringContextFactoryTest.java rename to micro-core/src/test/java/com/oath/micro/server/spring/SpringContextFactoryTest.java index a2e976475..d8ac4b5a0 100644 --- a/micro-core/src/test/java/com/aol/micro/server/spring/SpringContextFactoryTest.java +++ b/micro-core/src/test/java/com/oath/micro/server/spring/SpringContextFactoryTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.spring; +package com.oath.micro.server.spring; import static org.mockito.Matchers.anyObject; import static org.mockito.Mockito.mock; @@ -11,8 +11,8 @@ import org.junit.Test; import org.mockito.ArgumentCaptor; -import com.aol.micro.server.config.Config; -import com.aol.micro.server.config.Microserver; +import com.oath.micro.server.config.Config; +import com.oath.micro.server.config.Microserver; /** * Any new classes shoud be added into blackListedClasses for test to pass until proper solution with diff --git a/micro-core/src/test/java/com/oath/micro/server/utility/UsefulStaticMethodsTest.java b/micro-core/src/test/java/com/oath/micro/server/utility/UsefulStaticMethodsTest.java new file mode 100644 index 000000000..cb16e3aa9 --- /dev/null +++ b/micro-core/src/test/java/com/oath/micro/server/utility/UsefulStaticMethodsTest.java @@ -0,0 +1,17 @@ +package com.oath.micro.server.utility; + +import static com.oath.micro.server.utility.UsefulStaticMethods.either; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.*; + +import org.junit.Test; + +public class UsefulStaticMethodsTest { + + @Test + public void testEither() { + assertThat(either(null, "answer"), is("answer")); + assertThat(either("answer", "different"), is("answer")); + } + +} diff --git a/micro-core/src/test/java/nonautoscan/com/aol/micro/server/ConfiguredListener.java b/micro-core/src/test/java/nonautoscan/com/aol/micro/server/ConfiguredListener.java deleted file mode 100644 index d15010390..000000000 --- a/micro-core/src/test/java/nonautoscan/com/aol/micro/server/ConfiguredListener.java +++ /dev/null @@ -1,25 +0,0 @@ -package nonautoscan.com.aol.micro.server; - -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; - -import lombok.Getter; - -public class ConfiguredListener implements ServletContextListener { - - @Getter - private static volatile int called= 0; - - @Override - public void contextInitialized(ServletContextEvent sce) { - called ++; - - } - - @Override - public void contextDestroyed(ServletContextEvent sce) { - - - } - -} \ No newline at end of file diff --git a/micro-core/src/test/java/nonautoscan/com/aol/micro/server/PropertyFileConfigTest.java b/micro-core/src/test/java/nonautoscan/com/aol/micro/server/PropertyFileConfigTest.java deleted file mode 100644 index 71f038db3..000000000 --- a/micro-core/src/test/java/nonautoscan/com/aol/micro/server/PropertyFileConfigTest.java +++ /dev/null @@ -1,32 +0,0 @@ -package nonautoscan.com.aol.micro.server; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.junit.Assert.assertThat; - -import java.io.IOException; - -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.config.Config; -import com.aol.micro.server.spring.properties.PropertyFileConfig; -public class PropertyFileConfigTest { - - - - - - PropertyFileConfig config; - @Before - public void setUp() { - config = new PropertyFileConfig(); - } - - @Test - public void testPropertyPlaceholderConfigurer() throws IOException { - Config.instance(); - assertThat( config.propertyPlaceholderConfigurer(),notNullValue()); - } - - - -} diff --git a/micro-core/src/test/java/nonautoscan/com/aol/micro/server/ScheduleAndAsyncConfigTest.groovy b/micro-core/src/test/java/nonautoscan/com/aol/micro/server/ScheduleAndAsyncConfigTest.groovy deleted file mode 100644 index 071c36e08..000000000 --- a/micro-core/src/test/java/nonautoscan/com/aol/micro/server/ScheduleAndAsyncConfigTest.groovy +++ /dev/null @@ -1,56 +0,0 @@ -package nonautoscan.com.aol.micro.server - -import static org.junit.Assert.* -import groovy.transform.CompileStatic - -import org.junit.Before -import org.junit.Test -import org.mockito.Mockito -import org.springframework.scheduling.config.ScheduledTaskRegistrar -@CompileStatic -class ScheduleAndAsyncConfigTest { - - - ScheduleAndAsyncConfig config - @Before - public void setup(){ - config = new ScheduleAndAsyncConfig() - config.schedulerThreadPoolSize=3 - config.executorThreadPoolSize=3 - } - @Test - public void testSetExecutorThreadPoolSize() { - assert config.@executorThreadPoolSize==3 - } - - @Test - public void testSetSchedulerThreadPoolSize() { - - assert config.@schedulerThreadPoolSize==3 - } - - @Test - public void testGetAsyncExecutor() { - assert config.asyncExecutor !=null - } - - @Test - public void testConfigureTasks() { - ScheduledTaskRegistrar mock = Mockito.mock(ScheduledTaskRegistrar) - config.configureTasks(mock) - Mockito.verify(mock).setScheduler(Mockito.anyObject()) - } - - @Test - public void testTaskScheduler() { - assert config.taskScheduler()!=null - } - - @Test - public void testTaskExecutor() { - assert config.taskExecutor() != null - } - - - -} \ No newline at end of file diff --git a/micro-core/src/test/java/nonautoscan/com/oath/micro/server/ConfiguredListener.java b/micro-core/src/test/java/nonautoscan/com/oath/micro/server/ConfiguredListener.java new file mode 100644 index 000000000..cc1161808 --- /dev/null +++ b/micro-core/src/test/java/nonautoscan/com/oath/micro/server/ConfiguredListener.java @@ -0,0 +1,25 @@ +package nonautoscan.com.oath.micro.server; + +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; + +import lombok.Getter; + +public class ConfiguredListener implements ServletContextListener { + + @Getter + private static volatile int called= 0; + + @Override + public void contextInitialized(ServletContextEvent sce) { + called ++; + + } + + @Override + public void contextDestroyed(ServletContextEvent sce) { + + + } + +} \ No newline at end of file diff --git a/micro-core/src/test/java/nonautoscan/com/oath/micro/server/PropertyFileConfigTest.java b/micro-core/src/test/java/nonautoscan/com/oath/micro/server/PropertyFileConfigTest.java new file mode 100644 index 000000000..7f341009e --- /dev/null +++ b/micro-core/src/test/java/nonautoscan/com/oath/micro/server/PropertyFileConfigTest.java @@ -0,0 +1,32 @@ +package nonautoscan.com.oath.micro.server; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.junit.Assert.assertThat; + +import java.io.IOException; + +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.config.Config; +import com.oath.micro.server.spring.properties.PropertyFileConfig; +public class PropertyFileConfigTest { + + + + + + PropertyFileConfig config; + @Before + public void setUp() { + config = new PropertyFileConfig(); + } + + @Test + public void testPropertyPlaceholderConfigurer() throws IOException { + Config.instance(); + assertThat( config.propertyPlaceholderConfigurer(),notNullValue()); + } + + + +} diff --git a/micro-core/src/test/java/nonautoscan/com/oath/micro/server/ScheduleAndAsyncConfigTest.groovy b/micro-core/src/test/java/nonautoscan/com/oath/micro/server/ScheduleAndAsyncConfigTest.groovy new file mode 100644 index 000000000..3090aa418 --- /dev/null +++ b/micro-core/src/test/java/nonautoscan/com/oath/micro/server/ScheduleAndAsyncConfigTest.groovy @@ -0,0 +1,55 @@ +package nonautoscan.com.oath.micro.server + +import groovy.transform.CompileStatic + +import org.junit.Before +import org.junit.Test +import org.mockito.Mockito +import org.springframework.scheduling.config.ScheduledTaskRegistrar +@CompileStatic +class ScheduleAndAsyncConfigTest { + + + ScheduleAndAsyncConfig config + @Before + public void setup(){ + config = new ScheduleAndAsyncConfig() + config.schedulerThreadPoolSize=3 + config.executorThreadPoolSize=3 + } + @Test + public void testSetExecutorThreadPoolSize() { + assert config.@executorThreadPoolSize==3 + } + + @Test + public void testSetSchedulerThreadPoolSize() { + + assert config.@schedulerThreadPoolSize==3 + } + + @Test + public void testGetAsyncExecutor() { + assert config.asyncExecutor !=null + } + + @Test + public void testConfigureTasks() { + ScheduledTaskRegistrar mock = Mockito.mock(ScheduledTaskRegistrar) + config.configureTasks(mock) + Mockito.verify(mock).setScheduler(Mockito.anyObject()) + } + + @Test + public void testTaskScheduler() { + assert config.taskScheduler()!=null + } + + @Test + public void testTaskExecutor() { + assert config.taskExecutor() != null + } + + + +} \ No newline at end of file diff --git a/micro-core/src/test/resources/META-INF/services/com.aol.micro.server.Plugin b/micro-core/src/test/resources/META-INF/services/com.aol.micro.server.Plugin deleted file mode 100644 index a9bb6d2fb..000000000 --- a/micro-core/src/test/resources/META-INF/services/com.aol.micro.server.Plugin +++ /dev/null @@ -1 +0,0 @@ -com.aol.micro.server.module.MyPlugin \ No newline at end of file diff --git a/micro-core/src/test/resources/META-INF/services/com.oath.micro.server.Plugin b/micro-core/src/test/resources/META-INF/services/com.oath.micro.server.Plugin new file mode 100644 index 000000000..665e9a846 --- /dev/null +++ b/micro-core/src/test/resources/META-INF/services/com.oath.micro.server.Plugin @@ -0,0 +1 @@ +com.oath.micro.server.module.MyPlugin \ No newline at end of file diff --git a/micro-cors/src/main/java/com/aol/micro/server/web/cors/CorsPlugin.java b/micro-cors/src/main/java/com/aol/micro/server/web/cors/CorsPlugin.java deleted file mode 100644 index 6a02ca1c7..000000000 --- a/micro-cors/src/main/java/com/aol/micro/server/web/cors/CorsPlugin.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.aol.micro.server.web.cors; - - -import com.aol.micro.server.Plugin; -import cyclops.collections.immutable.PersistentSetX; -import cyclops.collections.mutable.SetX; - -import java.util.Set; - -public class CorsPlugin implements Plugin { - - @Override - public Set springClasses() { - return SetX.of(ConfigureBeans.class); - } - -} diff --git a/micro-cors/src/main/java/com/aol/micro/server/web/cors/ConfigureBeans.java b/micro-cors/src/main/java/com/oath/micro/server/web/cors/ConfigureBeans.java similarity index 95% rename from micro-cors/src/main/java/com/aol/micro/server/web/cors/ConfigureBeans.java rename to micro-cors/src/main/java/com/oath/micro/server/web/cors/ConfigureBeans.java index f20ade6fd..80542f952 100644 --- a/micro-cors/src/main/java/com/aol/micro/server/web/cors/ConfigureBeans.java +++ b/micro-cors/src/main/java/com/oath/micro/server/web/cors/ConfigureBeans.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.web.cors; +package com.oath.micro.server.web.cors; import java.util.HashMap; import java.util.Map; @@ -14,7 +14,7 @@ import org.springframework.context.annotation.Configuration; -import com.aol.micro.server.auto.discovery.FilterConfiguration; +import com.oath.micro.server.auto.discovery.FilterConfiguration; import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; diff --git a/micro-cors/src/main/java/com/oath/micro/server/web/cors/CorsPlugin.java b/micro-cors/src/main/java/com/oath/micro/server/web/cors/CorsPlugin.java new file mode 100644 index 000000000..d1d6463c6 --- /dev/null +++ b/micro-cors/src/main/java/com/oath/micro/server/web/cors/CorsPlugin.java @@ -0,0 +1,16 @@ +package com.oath.micro.server.web.cors; + + +import com.oath.micro.server.Plugin; +import cyclops.collections.mutable.SetX; + +import java.util.Set; + +public class CorsPlugin implements Plugin { + + @Override + public Set springClasses() { + return SetX.of(ConfigureBeans.class); + } + +} diff --git a/micro-cors/src/main/java/com/aol/micro/server/web/cors/CrossDomainFilter.java b/micro-cors/src/main/java/com/oath/micro/server/web/cors/CrossDomainFilter.java similarity index 75% rename from micro-cors/src/main/java/com/aol/micro/server/web/cors/CrossDomainFilter.java rename to micro-cors/src/main/java/com/oath/micro/server/web/cors/CrossDomainFilter.java index ef17f5ef4..1e47a4d50 100644 --- a/micro-cors/src/main/java/com/aol/micro/server/web/cors/CrossDomainFilter.java +++ b/micro-cors/src/main/java/com/oath/micro/server/web/cors/CrossDomainFilter.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.web.cors; +package com.oath.micro.server.web.cors; import java.io.IOException; @@ -10,14 +10,6 @@ import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletResponse; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.FilterConfiguration; - -import lombok.AllArgsConstructor; - public class CrossDomainFilter implements Filter { diff --git a/micro-cors/src/main/resources/META-INF/services/com.aol.micro.server.Plugin b/micro-cors/src/main/resources/META-INF/services/com.aol.micro.server.Plugin deleted file mode 100644 index f5ffeac13..000000000 --- a/micro-cors/src/main/resources/META-INF/services/com.aol.micro.server.Plugin +++ /dev/null @@ -1 +0,0 @@ -com.aol.micro.server.web.cors.CorsPlugin \ No newline at end of file diff --git a/micro-cors/src/main/resources/META-INF/services/com.oath.micro.server.Plugin b/micro-cors/src/main/resources/META-INF/services/com.oath.micro.server.Plugin new file mode 100644 index 000000000..fff80b6fb --- /dev/null +++ b/micro-cors/src/main/resources/META-INF/services/com.oath.micro.server.Plugin @@ -0,0 +1 @@ +com.oath.micro.server.web.cors.CorsPlugin \ No newline at end of file diff --git a/micro-cors/src/test/java/app/ebay/com/aol/micro/server/SingleClassTest.java b/micro-cors/src/test/java/app/ebay/com/aol/micro/server/SingleClassTest.java deleted file mode 100644 index d0f61f11c..000000000 --- a/micro-cors/src/test/java/app/ebay/com/aol/micro/server/SingleClassTest.java +++ /dev/null @@ -1,68 +0,0 @@ -package app.ebay.com.aol.micro.server; - -import static org.junit.Assert.*; - -import java.util.concurrent.ExecutionException; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Invocation.Builder; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.RestResource; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.testing.RestAgent; - -@Microserver -@Path("/single") -public class SingleClassTest implements RestResource{ - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer(){ - - server = new MicroserverApp( SingleClassTest.class, ()-> "simple-app"); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target("http://localhost:8080/simple-app/single/ping"); - - Builder request = resource.request(); - request.accept(MediaType.TEXT_PLAIN); - assertFalse(request.get().getHeaders().containsKey("Access-Control-Allow-Origin")); - - - - } - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "ok"; - } - - -} \ No newline at end of file diff --git a/micro-cors/src/test/java/app/ebay/com/oath/micro/server/SingleClassTest.java b/micro-cors/src/test/java/app/ebay/com/oath/micro/server/SingleClassTest.java new file mode 100644 index 000000000..8abafdf4b --- /dev/null +++ b/micro-cors/src/test/java/app/ebay/com/oath/micro/server/SingleClassTest.java @@ -0,0 +1,68 @@ +package app.ebay.com.oath.micro.server; + +import static org.junit.Assert.*; + +import java.util.concurrent.ExecutionException; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Invocation.Builder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.auto.discovery.RestResource; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.testing.RestAgent; + +@Microserver +@Path("/single") +public class SingleClassTest implements RestResource{ + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer(){ + + server = new MicroserverApp( SingleClassTest.class, ()-> "simple-app"); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target("http://localhost:8080/simple-app/single/ping"); + + Builder request = resource.request(); + request.accept(MediaType.TEXT_PLAIN); + assertFalse(request.get().getHeaders().containsKey("Access-Control-Allow-Origin")); + + + + } + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "ok"; + } + + +} \ No newline at end of file diff --git a/micro-cors/src/test/java/app/single/com/aol/micro/server/SingleClassTest.java b/micro-cors/src/test/java/app/single/com/aol/micro/server/SingleClassTest.java deleted file mode 100644 index f5e62ceda..000000000 --- a/micro-cors/src/test/java/app/single/com/aol/micro/server/SingleClassTest.java +++ /dev/null @@ -1,68 +0,0 @@ -package app.single.com.aol.micro.server; - -import static org.junit.Assert.assertTrue; - -import java.util.concurrent.ExecutionException; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Invocation.Builder; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.RestResource; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.testing.RestAgent; - -@Microserver(properties={"cors.simple","true"}) -@Path("/single") -public class SingleClassTest implements RestResource{ - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer(){ - - server = new MicroserverApp( SingleClassTest.class, ()-> "simple-app"); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target("http://localhost:8080/simple-app/single/ping"); - - Builder request = resource.request(); - request.accept(MediaType.TEXT_PLAIN); - assertTrue(request.get().getHeaders().containsKey("Access-Control-Allow-Origin")); - - - - } - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "ok"; - } - - -} \ No newline at end of file diff --git a/micro-cors/src/test/java/app/single/com/oath/micro/server/SingleClassTest.java b/micro-cors/src/test/java/app/single/com/oath/micro/server/SingleClassTest.java new file mode 100644 index 000000000..66f1f6cd9 --- /dev/null +++ b/micro-cors/src/test/java/app/single/com/oath/micro/server/SingleClassTest.java @@ -0,0 +1,68 @@ +package app.single.com.oath.micro.server; + +import static org.junit.Assert.assertTrue; + +import java.util.concurrent.ExecutionException; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Invocation.Builder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.auto.discovery.RestResource; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.testing.RestAgent; + +@Microserver(properties={"cors.simple","true"}) +@Path("/single") +public class SingleClassTest implements RestResource{ + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer(){ + + server = new MicroserverApp( SingleClassTest.class, ()-> "simple-app"); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target("http://localhost:8080/simple-app/single/ping"); + + Builder request = resource.request(); + request.accept(MediaType.TEXT_PLAIN); + assertTrue(request.get().getHeaders().containsKey("Access-Control-Allow-Origin")); + + + + } + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "ok"; + } + + +} \ No newline at end of file diff --git a/micro-cors/src/test/java/com/aol/micro/server/testing/RestAgent.java b/micro-cors/src/test/java/com/aol/micro/server/testing/RestAgent.java deleted file mode 100644 index ce204f810..000000000 --- a/micro-cors/src/test/java/com/aol/micro/server/testing/RestAgent.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.aol.micro.server.testing; - -import java.util.List; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.Invocation.Builder; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; - -import com.aol.micro.server.rest.jackson.JacksonUtil; - -public class RestAgent { - - - public String getJson(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.get(String.class); - - } - - public String get(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.TEXT_PLAIN); - - return request.get(String.class); - - } - - public T post(String url, Object payload,Class type) { - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); - } - - -} diff --git a/micro-cors/src/test/java/com/oath/micro/server/testing/RestAgent.java b/micro-cors/src/test/java/com/oath/micro/server/testing/RestAgent.java new file mode 100644 index 000000000..b2b86303e --- /dev/null +++ b/micro-cors/src/test/java/com/oath/micro/server/testing/RestAgent.java @@ -0,0 +1,53 @@ +package com.oath.micro.server.testing; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.Invocation.Builder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; + +import com.oath.micro.server.rest.jackson.JacksonUtil; + +public class RestAgent { + + + public String getJson(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.get(String.class); + + } + + public String get(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.TEXT_PLAIN); + + return request.get(String.class); + + } + + public T post(String url, Object payload,Class type) { + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); + } + + +} diff --git a/micro-cors/src/test/java/com/aol/micro/server/web/cors/ConfigureBeansTest.java b/micro-cors/src/test/java/com/oath/micro/server/web/cors/ConfigureBeansTest.java similarity index 96% rename from micro-cors/src/test/java/com/aol/micro/server/web/cors/ConfigureBeansTest.java rename to micro-cors/src/test/java/com/oath/micro/server/web/cors/ConfigureBeansTest.java index 8e6014be4..a7190a582 100644 --- a/micro-cors/src/test/java/com/aol/micro/server/web/cors/ConfigureBeansTest.java +++ b/micro-cors/src/test/java/com/oath/micro/server/web/cors/ConfigureBeansTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.web.cors; +package com.oath.micro.server.web.cors; import static org.hamcrest.Matchers.*; import static org.junit.Assert.fail; diff --git a/micro-cors/src/test/java/com/aol/micro/server/web/cors/CrossDomainFilterTest.java b/micro-cors/src/test/java/com/oath/micro/server/web/cors/CrossDomainFilterTest.java similarity index 94% rename from micro-cors/src/test/java/com/aol/micro/server/web/cors/CrossDomainFilterTest.java rename to micro-cors/src/test/java/com/oath/micro/server/web/cors/CrossDomainFilterTest.java index d886f17d8..5dcbee58c 100644 --- a/micro-cors/src/test/java/com/aol/micro/server/web/cors/CrossDomainFilterTest.java +++ b/micro-cors/src/test/java/com/oath/micro/server/web/cors/CrossDomainFilterTest.java @@ -1,6 +1,5 @@ -package com.aol.micro.server.web.cors; +package com.oath.micro.server.web.cors; -import static org.junit.Assert.*; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; diff --git a/micro-couchbase/src/main/java/com/aol/micro/server/couchbase/CouchbasePlugin.java b/micro-couchbase/src/main/java/com/aol/micro/server/couchbase/CouchbasePlugin.java deleted file mode 100644 index 686c85561..000000000 --- a/micro-couchbase/src/main/java/com/aol/micro/server/couchbase/CouchbasePlugin.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.aol.micro.server.couchbase; - -import com.aol.micro.server.Plugin; -import cyclops.collections.immutable.PersistentSetX; -import cyclops.collections.mutable.SetX; - -import java.util.Set; - -public class CouchbasePlugin implements Plugin { - - public Set springClasses() { - return SetX.of(ConfigureCouchbase.class); - } -} diff --git a/micro-couchbase/src/main/java/com/aol/micro/server/couchbase/ConfigureCouchbase.java b/micro-couchbase/src/main/java/com/oath/micro/server/couchbase/ConfigureCouchbase.java similarity index 96% rename from micro-couchbase/src/main/java/com/aol/micro/server/couchbase/ConfigureCouchbase.java rename to micro-couchbase/src/main/java/com/oath/micro/server/couchbase/ConfigureCouchbase.java index 162011c26..b718f065a 100644 --- a/micro-couchbase/src/main/java/com/aol/micro/server/couchbase/ConfigureCouchbase.java +++ b/micro-couchbase/src/main/java/com/oath/micro/server/couchbase/ConfigureCouchbase.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.couchbase; +package com.oath.micro.server.couchbase; import java.io.IOException; import java.net.URI; @@ -14,7 +14,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.util.StringUtils; -import com.aol.micro.server.couchbase.base.CouchbaseManifestComparator; +import com.oath.micro.server.couchbase.base.CouchbaseManifestComparator; import com.couchbase.client.CouchbaseClient; import com.couchbase.client.CouchbaseConnectionFactory; import com.couchbase.client.CouchbaseConnectionFactoryBuilder; diff --git a/micro-couchbase/src/main/java/com/aol/micro/server/couchbase/CouchbaseDistributedMapClient.java b/micro-couchbase/src/main/java/com/oath/micro/server/couchbase/CouchbaseDistributedMapClient.java similarity index 93% rename from micro-couchbase/src/main/java/com/aol/micro/server/couchbase/CouchbaseDistributedMapClient.java rename to micro-couchbase/src/main/java/com/oath/micro/server/couchbase/CouchbaseDistributedMapClient.java index 2c71c9a2f..70435ed9e 100644 --- a/micro-couchbase/src/main/java/com/aol/micro/server/couchbase/CouchbaseDistributedMapClient.java +++ b/micro-couchbase/src/main/java/com/oath/micro/server/couchbase/CouchbaseDistributedMapClient.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.couchbase; +package com.oath.micro.server.couchbase; import java.util.Optional; import java.util.concurrent.ExecutionException; @@ -7,7 +7,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.aol.micro.server.distributed.DistributedMap; +import com.oath.micro.server.distributed.DistributedMap; import com.couchbase.client.CouchbaseClient; public class CouchbaseDistributedMapClient implements DistributedMap { diff --git a/micro-couchbase/src/main/java/com/oath/micro/server/couchbase/CouchbasePlugin.java b/micro-couchbase/src/main/java/com/oath/micro/server/couchbase/CouchbasePlugin.java new file mode 100644 index 000000000..060f09f15 --- /dev/null +++ b/micro-couchbase/src/main/java/com/oath/micro/server/couchbase/CouchbasePlugin.java @@ -0,0 +1,13 @@ +package com.oath.micro.server.couchbase; + +import com.oath.micro.server.Plugin; +import cyclops.collections.mutable.SetX; + +import java.util.Set; + +public class CouchbasePlugin implements Plugin { + + public Set springClasses() { + return SetX.of(ConfigureCouchbase.class); + } +} diff --git a/micro-couchbase/src/main/java/com/aol/micro/server/couchbase/base/CouchbaseManifestComparator.java b/micro-couchbase/src/main/java/com/oath/micro/server/couchbase/base/CouchbaseManifestComparator.java similarity index 95% rename from micro-couchbase/src/main/java/com/aol/micro/server/couchbase/base/CouchbaseManifestComparator.java rename to micro-couchbase/src/main/java/com/oath/micro/server/couchbase/base/CouchbaseManifestComparator.java index a0ea6ccbc..8a85d475f 100644 --- a/micro-couchbase/src/main/java/com/aol/micro/server/couchbase/base/CouchbaseManifestComparator.java +++ b/micro-couchbase/src/main/java/com/oath/micro/server/couchbase/base/CouchbaseManifestComparator.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.couchbase.base; +package com.oath.micro.server.couchbase.base; import java.util.Date; import java.util.Optional; @@ -9,12 +9,12 @@ import org.slf4j.LoggerFactory; -import com.aol.micro.server.distributed.DistributedMap; -import com.aol.micro.server.manifest.Data; -import com.aol.micro.server.manifest.ManifestComparator; -import com.aol.micro.server.manifest.ManifestComparatorKeyNotFoundException; -import com.aol.micro.server.manifest.VersionedKey; -import com.aol.micro.server.rest.jackson.JacksonUtil; +import com.oath.micro.server.distributed.DistributedMap; +import com.oath.micro.server.manifest.Data; +import com.oath.micro.server.manifest.ManifestComparator; +import com.oath.micro.server.manifest.ManifestComparatorKeyNotFoundException; +import com.oath.micro.server.manifest.VersionedKey; +import com.oath.micro.server.rest.jackson.JacksonUtil; import lombok.AccessLevel; import lombok.AllArgsConstructor; diff --git a/micro-couchbase/src/main/resources/META-INF/services/com.aol.micro.server.Plugin b/micro-couchbase/src/main/resources/META-INF/services/com.aol.micro.server.Plugin deleted file mode 100644 index 2785a0dfc..000000000 --- a/micro-couchbase/src/main/resources/META-INF/services/com.aol.micro.server.Plugin +++ /dev/null @@ -1 +0,0 @@ -com.aol.micro.server.couchbase.CouchbasePlugin \ No newline at end of file diff --git a/micro-couchbase/src/main/resources/META-INF/services/com.oath.micro.server.Plugin b/micro-couchbase/src/main/resources/META-INF/services/com.oath.micro.server.Plugin new file mode 100644 index 000000000..4db0ad9b8 --- /dev/null +++ b/micro-couchbase/src/main/resources/META-INF/services/com.oath.micro.server.Plugin @@ -0,0 +1 @@ +com.oath.micro.server.couchbase.CouchbasePlugin \ No newline at end of file diff --git a/micro-couchbase/src/test/java/app/couchbase/distributed/map/com/aol/micro/server/CouchbaseResource.java b/micro-couchbase/src/test/java/app/couchbase/distributed/map/com/aol/micro/server/CouchbaseResource.java deleted file mode 100644 index 6676cb2b7..000000000 --- a/micro-couchbase/src/test/java/app/couchbase/distributed/map/com/aol/micro/server/CouchbaseResource.java +++ /dev/null @@ -1,35 +0,0 @@ -package app.couchbase.distributed.map.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; - -import org.springframework.beans.factory.annotation.Autowired; - -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.distributed.DistributedMap; - -@Path("/couchbase") -@Rest -public class CouchbaseResource { - - private final DistributedMap client; - - @Autowired - public CouchbaseResource(DistributedMap client) { - this.client = client; - } - - @GET - @Path("/get") - public String bucket() { - return client.get("hello") - .toString(); - } - - @GET - @Path("/put") - public String put() { - client.put("hello", "world"); - return "added"; - } -} diff --git a/micro-couchbase/src/test/java/app/couchbase/distributed/map/com/aol/micro/server/CouchbaseRunnerTest.java b/micro-couchbase/src/test/java/app/couchbase/distributed/map/com/aol/micro/server/CouchbaseRunnerTest.java deleted file mode 100644 index fe3159016..000000000 --- a/micro-couchbase/src/test/java/app/couchbase/distributed/map/com/aol/micro/server/CouchbaseRunnerTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package app.couchbase.distributed.map.com.aol.micro.server; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import org.couchbase.mock.CouchbaseMock; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.testing.RestAgent; - -@Microserver(properties = { "couchbaseServers", "http://localhost:8091/pools", "couchbasePassword", "", - "couchbaseBucket", "beer-sample" }) -public class CouchbaseRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - - @Before - public void startServer() { - try { - // couchbase already running? - rest.get("http://localhost:8091/pools"); - } catch (Exception e) { - // start mock couchbase - CouchbaseMock.main(new String[] { "-S" }); - } - server = new MicroserverApp( - ConfigurableModule.builder() - .context("simple-app") - .build()); - - server.start(); - - } - - @After - public void stopServer() { - server.stop(); - } - - @Test - @Ignore - public void runAppAndBasicTest() throws InterruptedException, ExecutionException { - rest.get("http://localhost:8080/simple-app/couchbase/put"); - assertThat(rest.get("http://localhost:8080/simple-app/couchbase/get"), containsString("world")); - - } - -} diff --git a/micro-couchbase/src/test/java/app/couchbase/distributed/map/com/oath/micro/server/CouchbaseResource.java b/micro-couchbase/src/test/java/app/couchbase/distributed/map/com/oath/micro/server/CouchbaseResource.java new file mode 100644 index 000000000..599a78018 --- /dev/null +++ b/micro-couchbase/src/test/java/app/couchbase/distributed/map/com/oath/micro/server/CouchbaseResource.java @@ -0,0 +1,35 @@ +package app.couchbase.distributed.map.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +import org.springframework.beans.factory.annotation.Autowired; + +import com.oath.micro.server.auto.discovery.Rest; +import com.oath.micro.server.distributed.DistributedMap; + +@Path("/couchbase") +@Rest +public class CouchbaseResource { + + private final DistributedMap client; + + @Autowired + public CouchbaseResource(DistributedMap client) { + this.client = client; + } + + @GET + @Path("/get") + public String bucket() { + return client.get("hello") + .toString(); + } + + @GET + @Path("/put") + public String put() { + client.put("hello", "world"); + return "added"; + } +} diff --git a/micro-couchbase/src/test/java/app/couchbase/distributed/map/com/oath/micro/server/CouchbaseRunnerTest.java b/micro-couchbase/src/test/java/app/couchbase/distributed/map/com/oath/micro/server/CouchbaseRunnerTest.java new file mode 100644 index 000000000..52de3a77d --- /dev/null +++ b/micro-couchbase/src/test/java/app/couchbase/distributed/map/com/oath/micro/server/CouchbaseRunnerTest.java @@ -0,0 +1,58 @@ +package app.couchbase.distributed.map.com.oath.micro.server; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import org.couchbase.mock.CouchbaseMock; +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.module.ConfigurableModule; +import com.oath.micro.server.testing.RestAgent; + +@Microserver(properties = { "couchbaseServers", "http://localhost:8091/pools", "couchbasePassword", "", + "couchbaseBucket", "beer-sample" }) +public class CouchbaseRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + + @Before + public void startServer() { + try { + // couchbase already running? + rest.get("http://localhost:8091/pools"); + } catch (Exception e) { + // start mock couchbase + CouchbaseMock.main(new String[] { "-S" }); + } + server = new MicroserverApp( + ConfigurableModule.builder() + .context("simple-app") + .build()); + + server.start(); + + } + + @After + public void stopServer() { + server.stop(); + } + + @Test + @Ignore + public void runAppAndBasicTest() throws InterruptedException, ExecutionException { + rest.get("http://localhost:8080/simple-app/couchbase/put"); + assertThat(rest.get("http://localhost:8080/simple-app/couchbase/get"), containsString("world")); + + } + +} diff --git a/micro-couchbase/src/test/java/app/couchbase/manifest/comparator/com/aol/micro/server/second/ManifestComparatorResource.java b/micro-couchbase/src/test/java/app/couchbase/manifest/comparator/com/aol/micro/server/second/ManifestComparatorResource.java deleted file mode 100644 index 7f863b81d..000000000 --- a/micro-couchbase/src/test/java/app/couchbase/manifest/comparator/com/aol/micro/server/second/ManifestComparatorResource.java +++ /dev/null @@ -1,45 +0,0 @@ -package app.couchbase.manifest.comparator.com.aol.micro.server.second; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; - -import org.springframework.beans.factory.annotation.Autowired; - -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.manifest.ManifestComparator; - -@Path("/comparator") -@Rest -public class ManifestComparatorResource { - - private volatile int count = 1; - private final ManifestComparator comparator; - - @Autowired - public ManifestComparatorResource(ManifestComparator comparator) { - this.comparator = comparator. withKey("test-key"); - } - - @GET - @Path("/increment") - public String bucket() { - comparator.saveAndIncrement("hello" + (count++)); - return "increment"; - } - - @GET - @Path("/get") - public String get() { - comparator.load(); - return comparator.getData() - .toString(); - - } - - @GET - @Path("/check") - public String check() { - return "" + !comparator.isOutOfDate(); - - } -} diff --git a/micro-couchbase/src/test/java/app/couchbase/manifest/comparator/com/aol/micro/server/second/ManifestComparatorRunnerTest.java b/micro-couchbase/src/test/java/app/couchbase/manifest/comparator/com/aol/micro/server/second/ManifestComparatorRunnerTest.java deleted file mode 100644 index e82d52397..000000000 --- a/micro-couchbase/src/test/java/app/couchbase/manifest/comparator/com/aol/micro/server/second/ManifestComparatorRunnerTest.java +++ /dev/null @@ -1,65 +0,0 @@ -package app.couchbase.manifest.comparator.com.aol.micro.server.second; - -import static org.hamcrest.CoreMatchers.equalTo; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import org.couchbase.mock.CouchbaseMock; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.testing.RestAgent; - -@Microserver(properties = { "couchbaseServers", "http://localhost:8091/pools", "couchbasePassword", "", - "couchbaseBucket", "beer-sample" }) -public class ManifestComparatorRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - - @Before - public void startServer() { - try { - // couchbase already running? - rest.get("http://localhost:8091/pools"); - } catch (Exception e) { - // start mock couchbase - CouchbaseMock.main(new String[] { "-S" }); - } - server = new MicroserverApp( - ConfigurableModule.builder() - .context("simple-app") - .build()); - - server.start(); - - } - - @After - public void stopServer() { - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException { - rest.get("http://localhost:8080/simple-app/comparator/increment"); - - assertThat(rest.get("http://localhost:8080/simple-app/comparator/check"), equalTo("true")); - assertThat(rest.get("http://localhost:8080/simple-app/comparator/get"), equalTo("hello1")); - rest.get("http://localhost:8080/simple-app/comparator/increment"); - assertThat(rest.get("http://localhost:8080/simple-app/comparator/get"), equalTo("hello2")); - - rest.get("http://localhost:8080/simple-app/comparator2/increment"); - - assertThat(rest.get("http://localhost:8080/simple-app/comparator/check"), equalTo("false")); - assertThat(rest.get("http://localhost:8080/simple-app/comparator/get"), equalTo("hellob")); - - } - -} diff --git a/micro-couchbase/src/test/java/app/couchbase/manifest/comparator/com/aol/micro/server/second/SecondComparatorResource.java b/micro-couchbase/src/test/java/app/couchbase/manifest/comparator/com/aol/micro/server/second/SecondComparatorResource.java deleted file mode 100644 index d928fc3c5..000000000 --- a/micro-couchbase/src/test/java/app/couchbase/manifest/comparator/com/aol/micro/server/second/SecondComparatorResource.java +++ /dev/null @@ -1,44 +0,0 @@ -package app.couchbase.manifest.comparator.com.aol.micro.server.second; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; - -import org.springframework.beans.factory.annotation.Autowired; - -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.manifest.ManifestComparator; - -@Path("/comparator2") -@Rest -public class SecondComparatorResource { - - private final ManifestComparator comparator; - - @Autowired - public SecondComparatorResource(ManifestComparator comparator) { - this.comparator = comparator.withKey("test-key"); - } - - @GET - @Path("/increment") - public String bucket() { - comparator.saveAndIncrement("hellob"); - return "increment"; - } - - @GET - @Path("/get") - public String get() { - comparator.load(); - return comparator.getData() - .toString(); - - } - - @GET - @Path("/check") - public String check() { - return "" + !comparator.isOutOfDate(); - - } -} \ No newline at end of file diff --git a/micro-couchbase/src/test/java/app/couchbase/manifest/comparator/com/oath/micro/server/second/ManifestComparatorResource.java b/micro-couchbase/src/test/java/app/couchbase/manifest/comparator/com/oath/micro/server/second/ManifestComparatorResource.java new file mode 100644 index 000000000..f584b12bf --- /dev/null +++ b/micro-couchbase/src/test/java/app/couchbase/manifest/comparator/com/oath/micro/server/second/ManifestComparatorResource.java @@ -0,0 +1,45 @@ +package app.couchbase.manifest.comparator.com.oath.micro.server.second; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +import org.springframework.beans.factory.annotation.Autowired; + +import com.oath.micro.server.auto.discovery.Rest; +import com.oath.micro.server.manifest.ManifestComparator; + +@Path("/comparator") +@Rest +public class ManifestComparatorResource { + + private volatile int count = 1; + private final ManifestComparator comparator; + + @Autowired + public ManifestComparatorResource(ManifestComparator comparator) { + this.comparator = comparator. withKey("test-key"); + } + + @GET + @Path("/increment") + public String bucket() { + comparator.saveAndIncrement("hello" + (count++)); + return "increment"; + } + + @GET + @Path("/get") + public String get() { + comparator.load(); + return comparator.getData() + .toString(); + + } + + @GET + @Path("/check") + public String check() { + return "" + !comparator.isOutOfDate(); + + } +} diff --git a/micro-couchbase/src/test/java/app/couchbase/manifest/comparator/com/oath/micro/server/second/ManifestComparatorRunnerTest.java b/micro-couchbase/src/test/java/app/couchbase/manifest/comparator/com/oath/micro/server/second/ManifestComparatorRunnerTest.java new file mode 100644 index 000000000..a3c46d493 --- /dev/null +++ b/micro-couchbase/src/test/java/app/couchbase/manifest/comparator/com/oath/micro/server/second/ManifestComparatorRunnerTest.java @@ -0,0 +1,65 @@ +package app.couchbase.manifest.comparator.com.oath.micro.server.second; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import org.couchbase.mock.CouchbaseMock; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.module.ConfigurableModule; +import com.oath.micro.server.testing.RestAgent; + +@Microserver(properties = { "couchbaseServers", "http://localhost:8091/pools", "couchbasePassword", "", + "couchbaseBucket", "beer-sample" }) +public class ManifestComparatorRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + + @Before + public void startServer() { + try { + // couchbase already running? + rest.get("http://localhost:8091/pools"); + } catch (Exception e) { + // start mock couchbase + CouchbaseMock.main(new String[] { "-S" }); + } + server = new MicroserverApp( + ConfigurableModule.builder() + .context("simple-app") + .build()); + + server.start(); + + } + + @After + public void stopServer() { + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException { + rest.get("http://localhost:8080/simple-app/comparator/increment"); + + assertThat(rest.get("http://localhost:8080/simple-app/comparator/check"), equalTo("true")); + assertThat(rest.get("http://localhost:8080/simple-app/comparator/get"), equalTo("hello1")); + rest.get("http://localhost:8080/simple-app/comparator/increment"); + assertThat(rest.get("http://localhost:8080/simple-app/comparator/get"), equalTo("hello2")); + + rest.get("http://localhost:8080/simple-app/comparator2/increment"); + + assertThat(rest.get("http://localhost:8080/simple-app/comparator/check"), equalTo("false")); + assertThat(rest.get("http://localhost:8080/simple-app/comparator/get"), equalTo("hellob")); + + } + +} diff --git a/micro-couchbase/src/test/java/app/couchbase/manifest/comparator/com/oath/micro/server/second/SecondComparatorResource.java b/micro-couchbase/src/test/java/app/couchbase/manifest/comparator/com/oath/micro/server/second/SecondComparatorResource.java new file mode 100644 index 000000000..c69e7735b --- /dev/null +++ b/micro-couchbase/src/test/java/app/couchbase/manifest/comparator/com/oath/micro/server/second/SecondComparatorResource.java @@ -0,0 +1,44 @@ +package app.couchbase.manifest.comparator.com.oath.micro.server.second; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +import org.springframework.beans.factory.annotation.Autowired; + +import com.oath.micro.server.auto.discovery.Rest; +import com.oath.micro.server.manifest.ManifestComparator; + +@Path("/comparator2") +@Rest +public class SecondComparatorResource { + + private final ManifestComparator comparator; + + @Autowired + public SecondComparatorResource(ManifestComparator comparator) { + this.comparator = comparator.withKey("test-key"); + } + + @GET + @Path("/increment") + public String bucket() { + comparator.saveAndIncrement("hellob"); + return "increment"; + } + + @GET + @Path("/get") + public String get() { + comparator.load(); + return comparator.getData() + .toString(); + + } + + @GET + @Path("/check") + public String check() { + return "" + !comparator.isOutOfDate(); + + } +} \ No newline at end of file diff --git a/micro-couchbase/src/test/java/com/aol/micro/server/couchbase/MockEntity.java b/micro-couchbase/src/test/java/com/aol/micro/server/couchbase/MockEntity.java deleted file mode 100644 index 7e1b42f32..000000000 --- a/micro-couchbase/src/test/java/com/aol/micro/server/couchbase/MockEntity.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.aol.micro.server.couchbase; - -public class MockEntity { - -} diff --git a/micro-couchbase/src/test/java/com/aol/micro/server/couchbase/SimpleCouchbaseClientTest.groovy b/micro-couchbase/src/test/java/com/aol/micro/server/couchbase/SimpleCouchbaseClientTest.groovy deleted file mode 100644 index 696bc1096..000000000 --- a/micro-couchbase/src/test/java/com/aol/micro/server/couchbase/SimpleCouchbaseClientTest.groovy +++ /dev/null @@ -1 +0,0 @@ -package com.aol.micro.server.couchbase; diff --git a/micro-couchbase/src/test/java/com/aol/micro/server/couchbase/base/ManifestComparatorTest.groovy b/micro-couchbase/src/test/java/com/aol/micro/server/couchbase/base/ManifestComparatorTest.groovy deleted file mode 100644 index cc56352af..000000000 --- a/micro-couchbase/src/test/java/com/aol/micro/server/couchbase/base/ManifestComparatorTest.groovy +++ /dev/null @@ -1 +0,0 @@ -package com.aol.micro.server.couchbase.base; diff --git a/micro-couchbase/src/test/java/com/aol/micro/server/testing/RestAgent.java b/micro-couchbase/src/test/java/com/aol/micro/server/testing/RestAgent.java deleted file mode 100644 index d6ff3c017..000000000 --- a/micro-couchbase/src/test/java/com/aol/micro/server/testing/RestAgent.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.aol.micro.server.testing; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Invocation.Builder; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; - -public class RestAgent { - - public String get(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.get(String.class); - - } - -} diff --git a/micro-couchbase/src/test/java/com/aol/micro/server/couchbase/ConfigureCouchbaseTest.java b/micro-couchbase/src/test/java/com/oath/micro/server/couchbase/ConfigureCouchbaseTest.java similarity index 91% rename from micro-couchbase/src/test/java/com/aol/micro/server/couchbase/ConfigureCouchbaseTest.java rename to micro-couchbase/src/test/java/com/oath/micro/server/couchbase/ConfigureCouchbaseTest.java index 3ce542b9a..b12d6d16f 100644 --- a/micro-couchbase/src/test/java/com/aol/micro/server/couchbase/ConfigureCouchbaseTest.java +++ b/micro-couchbase/src/test/java/com/oath/micro/server/couchbase/ConfigureCouchbaseTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.couchbase; +package com.oath.micro.server.couchbase; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; @@ -11,7 +11,7 @@ import org.junit.Before; import org.junit.Test; -import com.aol.micro.server.distributed.DistributedMap; +import com.oath.micro.server.distributed.DistributedMap; public class ConfigureCouchbaseTest { diff --git a/micro-couchbase/src/test/java/com/oath/micro/server/couchbase/MockEntity.java b/micro-couchbase/src/test/java/com/oath/micro/server/couchbase/MockEntity.java new file mode 100644 index 000000000..238164228 --- /dev/null +++ b/micro-couchbase/src/test/java/com/oath/micro/server/couchbase/MockEntity.java @@ -0,0 +1,5 @@ +package com.oath.micro.server.couchbase; + +public class MockEntity { + +} diff --git a/micro-couchbase/src/test/java/com/aol/micro/server/couchbase/SimpleCouchbaseClientConnectionTest.groovy b/micro-couchbase/src/test/java/com/oath/micro/server/couchbase/SimpleCouchbaseClientConnectionTest.groovy similarity index 89% rename from micro-couchbase/src/test/java/com/aol/micro/server/couchbase/SimpleCouchbaseClientConnectionTest.groovy rename to micro-couchbase/src/test/java/com/oath/micro/server/couchbase/SimpleCouchbaseClientConnectionTest.groovy index 0c24348e6..0aaa75869 100644 --- a/micro-couchbase/src/test/java/com/aol/micro/server/couchbase/SimpleCouchbaseClientConnectionTest.groovy +++ b/micro-couchbase/src/test/java/com/oath/micro/server/couchbase/SimpleCouchbaseClientConnectionTest.groovy @@ -1,4 +1,4 @@ -package com.aol.micro.server.couchbase; +package com.oath.micro.server.couchbase; import static org.hamcrest.Matchers.is import static org.junit.Assert.* @@ -8,7 +8,7 @@ import org.junit.Before import org.junit.Test import org.mockito.Mockito -import com.aol.micro.server.distributed.DistributedMap; +import com.oath.micro.server.distributed.DistributedMap; import com.couchbase.client.CouchbaseClient class SimpleCouchbaseClientConnectionTest { diff --git a/micro-couchbase/src/test/java/com/oath/micro/server/couchbase/SimpleCouchbaseClientTest.groovy b/micro-couchbase/src/test/java/com/oath/micro/server/couchbase/SimpleCouchbaseClientTest.groovy new file mode 100644 index 000000000..abd584458 --- /dev/null +++ b/micro-couchbase/src/test/java/com/oath/micro/server/couchbase/SimpleCouchbaseClientTest.groovy @@ -0,0 +1 @@ +package com.oath.micro.server.couchbase; diff --git a/micro-couchbase/src/test/java/com/aol/micro/server/couchbase/base/ManifestComparatorKeyNotFoundExceptionTest.java b/micro-couchbase/src/test/java/com/oath/micro/server/couchbase/base/ManifestComparatorKeyNotFoundExceptionTest.java similarity index 80% rename from micro-couchbase/src/test/java/com/aol/micro/server/couchbase/base/ManifestComparatorKeyNotFoundExceptionTest.java rename to micro-couchbase/src/test/java/com/oath/micro/server/couchbase/base/ManifestComparatorKeyNotFoundExceptionTest.java index 2dd6fb910..92a9b01fd 100644 --- a/micro-couchbase/src/test/java/com/aol/micro/server/couchbase/base/ManifestComparatorKeyNotFoundExceptionTest.java +++ b/micro-couchbase/src/test/java/com/oath/micro/server/couchbase/base/ManifestComparatorKeyNotFoundExceptionTest.java @@ -1,11 +1,11 @@ -package com.aol.micro.server.couchbase.base; +package com.oath.micro.server.couchbase.base; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; import org.junit.Test; -import com.aol.micro.server.manifest.ManifestComparatorKeyNotFoundException; +import com.oath.micro.server.manifest.ManifestComparatorKeyNotFoundException; public class ManifestComparatorKeyNotFoundExceptionTest { diff --git a/micro-couchbase/src/test/java/com/oath/micro/server/couchbase/base/ManifestComparatorTest.groovy b/micro-couchbase/src/test/java/com/oath/micro/server/couchbase/base/ManifestComparatorTest.groovy new file mode 100644 index 000000000..670b26b32 --- /dev/null +++ b/micro-couchbase/src/test/java/com/oath/micro/server/couchbase/base/ManifestComparatorTest.groovy @@ -0,0 +1 @@ +package com.oath.micro.server.couchbase.base; diff --git a/micro-couchbase/src/test/java/com/oath/micro/server/testing/RestAgent.java b/micro-couchbase/src/test/java/com/oath/micro/server/testing/RestAgent.java new file mode 100644 index 000000000..7b82e1257 --- /dev/null +++ b/micro-couchbase/src/test/java/com/oath/micro/server/testing/RestAgent.java @@ -0,0 +1,24 @@ +package com.oath.micro.server.testing; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Invocation.Builder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; + +public class RestAgent { + + public String get(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.get(String.class); + + } + +} diff --git a/micro-curator/src/integration/java/com/aol/micro/server/curator/lock/IntegrationTest.java b/micro-curator/src/integration/java/com/oath/micro/server/curator/lock/IntegrationTest.java similarity index 95% rename from micro-curator/src/integration/java/com/aol/micro/server/curator/lock/IntegrationTest.java rename to micro-curator/src/integration/java/com/oath/micro/server/curator/lock/IntegrationTest.java index dd5be2033..e2afd7b9a 100644 --- a/micro-curator/src/integration/java/com/aol/micro/server/curator/lock/IntegrationTest.java +++ b/micro-curator/src/integration/java/com/oath/micro/server/curator/lock/IntegrationTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.curator.lock; +package com.oath.micro.server.curator.lock; import java.io.IOException; import java.util.Properties; @@ -12,7 +12,7 @@ import org.junit.Before; import org.junit.Test; -import com.aol.micro.server.dist.lock.DistributedLockService; +import com.oath.micro.server.dist.lock.DistributedLockService; public class IntegrationTest { diff --git a/micro-curator/src/main/java/com/aol/micro/server/curator/CuratorPlugin.java b/micro-curator/src/main/java/com/aol/micro/server/curator/CuratorPlugin.java deleted file mode 100644 index dd1fe6ed4..000000000 --- a/micro-curator/src/main/java/com/aol/micro/server/curator/CuratorPlugin.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.aol.micro.server.curator; - -import com.aol.micro.server.Plugin; -import com.aol.micro.server.curator.lock.CuratorDistributedLockServiceProvider; -import cyclops.collections.immutable.PersistentSetX; -import cyclops.collections.mutable.SetX; - -import java.util.Set; - -public class CuratorPlugin implements Plugin { - @Override - public Set springClasses() { - return SetX.of(CuratorDistributedLockServiceProvider.class); - } -} diff --git a/micro-curator/src/main/java/com/oath/micro/server/curator/CuratorPlugin.java b/micro-curator/src/main/java/com/oath/micro/server/curator/CuratorPlugin.java new file mode 100644 index 000000000..d3878056e --- /dev/null +++ b/micro-curator/src/main/java/com/oath/micro/server/curator/CuratorPlugin.java @@ -0,0 +1,14 @@ +package com.oath.micro.server.curator; + +import com.oath.micro.server.Plugin; +import com.oath.micro.server.curator.lock.CuratorDistributedLockServiceProvider; +import cyclops.collections.mutable.SetX; + +import java.util.Set; + +public class CuratorPlugin implements Plugin { + @Override + public Set springClasses() { + return SetX.of(CuratorDistributedLockServiceProvider.class); + } +} diff --git a/micro-curator/src/main/java/com/aol/micro/server/curator/lock/CuratorDistributedLockServiceProvider.java b/micro-curator/src/main/java/com/oath/micro/server/curator/lock/CuratorDistributedLockServiceProvider.java similarity index 93% rename from micro-curator/src/main/java/com/aol/micro/server/curator/lock/CuratorDistributedLockServiceProvider.java rename to micro-curator/src/main/java/com/oath/micro/server/curator/lock/CuratorDistributedLockServiceProvider.java index 6964ad43b..948a97429 100644 --- a/micro-curator/src/main/java/com/aol/micro/server/curator/lock/CuratorDistributedLockServiceProvider.java +++ b/micro-curator/src/main/java/com/oath/micro/server/curator/lock/CuratorDistributedLockServiceProvider.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.curator.lock; +package com.oath.micro.server.curator.lock; import org.apache.curator.RetryPolicy; import org.apache.curator.framework.CuratorFramework; @@ -8,7 +8,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; -import com.aol.micro.server.dist.lock.DistributedLockService; +import com.oath.micro.server.dist.lock.DistributedLockService; @Component public class CuratorDistributedLockServiceProvider { diff --git a/micro-curator/src/main/java/com/aol/micro/server/curator/lock/DistributedLockServiceCuratorImpl.java b/micro-curator/src/main/java/com/oath/micro/server/curator/lock/DistributedLockServiceCuratorImpl.java similarity index 96% rename from micro-curator/src/main/java/com/aol/micro/server/curator/lock/DistributedLockServiceCuratorImpl.java rename to micro-curator/src/main/java/com/oath/micro/server/curator/lock/DistributedLockServiceCuratorImpl.java index 3cfe14e82..46c97b0d1 100644 --- a/micro-curator/src/main/java/com/aol/micro/server/curator/lock/DistributedLockServiceCuratorImpl.java +++ b/micro-curator/src/main/java/com/oath/micro/server/curator/lock/DistributedLockServiceCuratorImpl.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.curator.lock; +package com.oath.micro.server.curator.lock; import java.util.ArrayList; import java.util.Collection; @@ -14,7 +14,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.aol.micro.server.dist.lock.DistributedLockService; +import com.oath.micro.server.dist.lock.DistributedLockService; import lombok.AllArgsConstructor; import lombok.experimental.Wither; diff --git a/micro-curator/src/main/resources/META-INF/services/com.aol.micro.server.Plugin b/micro-curator/src/main/resources/META-INF/services/com.aol.micro.server.Plugin deleted file mode 100644 index f4f8779c1..000000000 --- a/micro-curator/src/main/resources/META-INF/services/com.aol.micro.server.Plugin +++ /dev/null @@ -1 +0,0 @@ -com.aol.micro.server.curator.CuratorPlugin \ No newline at end of file diff --git a/micro-curator/src/main/resources/META-INF/services/com.oath.micro.server.Plugin b/micro-curator/src/main/resources/META-INF/services/com.oath.micro.server.Plugin new file mode 100644 index 000000000..df740a31a --- /dev/null +++ b/micro-curator/src/main/resources/META-INF/services/com.oath.micro.server.Plugin @@ -0,0 +1 @@ +com.oath.micro.server.curator.CuratorPlugin \ No newline at end of file diff --git a/micro-curator/src/test/java/app/prototype/com/aol/micro/server/CuratorStatusResource.java b/micro-curator/src/test/java/app/prototype/com/aol/micro/server/CuratorStatusResource.java index 56a3af888..45d1eddf9 100644 --- a/micro-curator/src/test/java/app/prototype/com/aol/micro/server/CuratorStatusResource.java +++ b/micro-curator/src/test/java/app/prototype/com/aol/micro/server/CuratorStatusResource.java @@ -5,9 +5,9 @@ import org.springframework.beans.factory.annotation.Autowired; -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.curator.lock.CuratorDistributedLockServiceProvider; -import com.aol.micro.server.dist.lock.DistributedLockService; +import com.oath.micro.server.auto.discovery.Rest; +import com.oath.micro.server.curator.lock.CuratorDistributedLockServiceProvider; +import com.oath.micro.server.dist.lock.DistributedLockService; @Rest @Path("/status") diff --git a/micro-curator/src/test/java/app/prototype/com/aol/micro/server/DummyLock.java b/micro-curator/src/test/java/app/prototype/com/aol/micro/server/DummyLock.java index c532762cc..d457c0c65 100644 --- a/micro-curator/src/test/java/app/prototype/com/aol/micro/server/DummyLock.java +++ b/micro-curator/src/test/java/app/prototype/com/aol/micro/server/DummyLock.java @@ -2,7 +2,7 @@ import org.springframework.stereotype.Component; -import com.aol.micro.server.dist.lock.DistributedLockService; +import com.oath.micro.server.dist.lock.DistributedLockService; @Component public class DummyLock implements DistributedLockService { diff --git a/micro-curator/src/test/java/app/prototype/com/aol/micro/server/PrototypeLockCuratorRunnerTest.java b/micro-curator/src/test/java/app/prototype/com/aol/micro/server/PrototypeLockCuratorRunnerTest.java index 4abe2d2f7..a763a983c 100644 --- a/micro-curator/src/test/java/app/prototype/com/aol/micro/server/PrototypeLockCuratorRunnerTest.java +++ b/micro-curator/src/test/java/app/prototype/com/aol/micro/server/PrototypeLockCuratorRunnerTest.java @@ -6,7 +6,6 @@ import java.io.File; import java.io.IOException; -import java.util.Arrays; import java.util.concurrent.ExecutionException; import org.apache.commons.io.FileUtils; @@ -14,10 +13,9 @@ import org.junit.Before; import org.junit.Test; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.testing.RestAgent; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.testing.RestAgent; @Microserver public class PrototypeLockCuratorRunnerTest { diff --git a/micro-curator/src/test/java/app/singleton/com/aol/micro/server/copy/DummyLock.java b/micro-curator/src/test/java/app/singleton/com/aol/micro/server/copy/DummyLock.java deleted file mode 100644 index 9365321aa..000000000 --- a/micro-curator/src/test/java/app/singleton/com/aol/micro/server/copy/DummyLock.java +++ /dev/null @@ -1,20 +0,0 @@ -package app.singleton.com.aol.micro.server.copy; - -import org.springframework.stereotype.Component; - -import com.aol.micro.server.dist.lock.DistributedLockService; - -@Component -public class DummyLock implements DistributedLockService { - - @Override - public boolean tryLock(String key) { - return false; - } - - @Override - public boolean tryReleaseLock(String key) { - return false; - } - -} diff --git a/micro-curator/src/test/java/app/singleton/com/aol/micro/server/copy/CuratorStatusResource.java b/micro-curator/src/test/java/app/singleton/com/oath/micro/server/copy/CuratorStatusResource.java similarity index 75% rename from micro-curator/src/test/java/app/singleton/com/aol/micro/server/copy/CuratorStatusResource.java rename to micro-curator/src/test/java/app/singleton/com/oath/micro/server/copy/CuratorStatusResource.java index 331b6d4cc..d8ae88e45 100644 --- a/micro-curator/src/test/java/app/singleton/com/aol/micro/server/copy/CuratorStatusResource.java +++ b/micro-curator/src/test/java/app/singleton/com/oath/micro/server/copy/CuratorStatusResource.java @@ -1,13 +1,13 @@ -package app.singleton.com.aol.micro.server.copy; +package app.singleton.com.oath.micro.server.copy; import javax.ws.rs.GET; import javax.ws.rs.Path; import org.springframework.beans.factory.annotation.Autowired; -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.curator.lock.CuratorDistributedLockServiceProvider; -import com.aol.micro.server.dist.lock.DistributedLockService; +import com.oath.micro.server.auto.discovery.Rest; +import com.oath.micro.server.curator.lock.CuratorDistributedLockServiceProvider; +import com.oath.micro.server.dist.lock.DistributedLockService; @Rest(isSingleton=true) @Path("/status") diff --git a/micro-curator/src/test/java/app/singleton/com/oath/micro/server/copy/DummyLock.java b/micro-curator/src/test/java/app/singleton/com/oath/micro/server/copy/DummyLock.java new file mode 100644 index 000000000..851b8dcf9 --- /dev/null +++ b/micro-curator/src/test/java/app/singleton/com/oath/micro/server/copy/DummyLock.java @@ -0,0 +1,20 @@ +package app.singleton.com.oath.micro.server.copy; + +import org.springframework.stereotype.Component; + +import com.oath.micro.server.dist.lock.DistributedLockService; + +@Component +public class DummyLock implements DistributedLockService { + + @Override + public boolean tryLock(String key) { + return false; + } + + @Override + public boolean tryReleaseLock(String key) { + return false; + } + +} diff --git a/micro-curator/src/test/java/app/singleton/com/aol/micro/server/copy/KeepLockCuratorRunnerTest.java b/micro-curator/src/test/java/app/singleton/com/oath/micro/server/copy/KeepLockCuratorRunnerTest.java similarity index 84% rename from micro-curator/src/test/java/app/singleton/com/aol/micro/server/copy/KeepLockCuratorRunnerTest.java rename to micro-curator/src/test/java/app/singleton/com/oath/micro/server/copy/KeepLockCuratorRunnerTest.java index 44e76be3e..6d35732c1 100644 --- a/micro-curator/src/test/java/app/singleton/com/aol/micro/server/copy/KeepLockCuratorRunnerTest.java +++ b/micro-curator/src/test/java/app/singleton/com/oath/micro/server/copy/KeepLockCuratorRunnerTest.java @@ -1,4 +1,4 @@ -package app.singleton.com.aol.micro.server.copy; +package app.singleton.com.oath.micro.server.copy; import static org.hamcrest.CoreMatchers.is; @@ -13,9 +13,9 @@ import org.junit.Before; import org.junit.Test; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.testing.RestAgent; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.testing.RestAgent; @Microserver public class KeepLockCuratorRunnerTest { diff --git a/micro-curator/src/test/java/app/singleton/com/aol/micro/server/copy/Zookeeper.java b/micro-curator/src/test/java/app/singleton/com/oath/micro/server/copy/Zookeeper.java similarity index 90% rename from micro-curator/src/test/java/app/singleton/com/aol/micro/server/copy/Zookeeper.java rename to micro-curator/src/test/java/app/singleton/com/oath/micro/server/copy/Zookeeper.java index fc35f1a4d..8da99e7d0 100644 --- a/micro-curator/src/test/java/app/singleton/com/aol/micro/server/copy/Zookeeper.java +++ b/micro-curator/src/test/java/app/singleton/com/oath/micro/server/copy/Zookeeper.java @@ -1,15 +1,12 @@ -package app.singleton.com.aol.micro.server.copy; +package app.singleton.com.oath.micro.server.copy; import java.io.IOException; import java.util.Properties; -import javax.annotation.PostConstruct; - import org.apache.zookeeper.server.ServerConfig; import org.apache.zookeeper.server.ZooKeeperServerMain; import org.apache.zookeeper.server.admin.AdminServer.AdminServerException; import org.apache.zookeeper.server.quorum.QuorumPeerConfig; -import org.springframework.stereotype.Component; public class Zookeeper { diff --git a/micro-curator/src/test/java/com/aol/micro/server/testing/RestAgent.java b/micro-curator/src/test/java/com/aol/micro/server/testing/RestAgent.java deleted file mode 100644 index ce204f810..000000000 --- a/micro-curator/src/test/java/com/aol/micro/server/testing/RestAgent.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.aol.micro.server.testing; - -import java.util.List; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.Invocation.Builder; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; - -import com.aol.micro.server.rest.jackson.JacksonUtil; - -public class RestAgent { - - - public String getJson(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.get(String.class); - - } - - public String get(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.TEXT_PLAIN); - - return request.get(String.class); - - } - - public T post(String url, Object payload,Class type) { - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); - } - - -} diff --git a/micro-curator/src/test/java/com/aol/micro/server/curator/lock/DistributedLockServiceCuratorImplTest.java b/micro-curator/src/test/java/com/oath/micro/server/curator/lock/DistributedLockServiceCuratorImplTest.java similarity index 97% rename from micro-curator/src/test/java/com/aol/micro/server/curator/lock/DistributedLockServiceCuratorImplTest.java rename to micro-curator/src/test/java/com/oath/micro/server/curator/lock/DistributedLockServiceCuratorImplTest.java index a968c8916..aace413f7 100644 --- a/micro-curator/src/test/java/com/aol/micro/server/curator/lock/DistributedLockServiceCuratorImplTest.java +++ b/micro-curator/src/test/java/com/oath/micro/server/curator/lock/DistributedLockServiceCuratorImplTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.curator.lock; +package com.oath.micro.server.curator.lock; import static org.mockito.Matchers.anyObject; import static org.mockito.Matchers.anyString; diff --git a/micro-curator/src/test/java/com/oath/micro/server/testing/RestAgent.java b/micro-curator/src/test/java/com/oath/micro/server/testing/RestAgent.java new file mode 100644 index 000000000..b2b86303e --- /dev/null +++ b/micro-curator/src/test/java/com/oath/micro/server/testing/RestAgent.java @@ -0,0 +1,53 @@ +package com.oath.micro.server.testing; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.Invocation.Builder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; + +import com.oath.micro.server.rest.jackson.JacksonUtil; + +public class RestAgent { + + + public String getJson(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.get(String.class); + + } + + public String get(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.TEXT_PLAIN); + + return request.get(String.class); + + } + + public T post(String url, Object payload,Class type) { + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); + } + + +} diff --git a/micro-dbcp/src/main/java/com/aol/micro/server/spring/DBCPPlugin.java b/micro-dbcp/src/main/java/com/aol/micro/server/spring/DBCPPlugin.java deleted file mode 100644 index 3714fd219..000000000 --- a/micro-dbcp/src/main/java/com/aol/micro/server/spring/DBCPPlugin.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.aol.micro.server.spring; - -import java.util.Set; -import java.util.function.Function; - -import javax.servlet.ServletContextListener; - - -import com.aol.micro.server.Plugin; -import com.aol.micro.server.servers.model.ServerData; -import com.aol.micro.server.spring.datasource.DBCPConfig; -import com.aol.micro.server.spring.datasource.DBCPDataSourceBuilder; -import cyclops.collections.immutable.PersistentSetX; -import cyclops.collections.mutable.SetX; - -/** - * - * @author kewang - * - */ -public class DBCPPlugin implements Plugin { - - @Override - public Set springClasses() { - return SetX.of(DBCPConfig.class, DBCPDataSourceBuilder.class); - } - - - -} diff --git a/micro-dbcp/src/main/java/com/oath/micro/server/spring/DBCPPlugin.java b/micro-dbcp/src/main/java/com/oath/micro/server/spring/DBCPPlugin.java new file mode 100644 index 000000000..4ce66edbe --- /dev/null +++ b/micro-dbcp/src/main/java/com/oath/micro/server/spring/DBCPPlugin.java @@ -0,0 +1,25 @@ +package com.oath.micro.server.spring; + +import java.util.Set; + + +import com.oath.micro.server.Plugin; +import com.oath.micro.server.spring.datasource.DBCPConfig; +import com.oath.micro.server.spring.datasource.DBCPDataSourceBuilder; +import cyclops.collections.mutable.SetX; + +/** + * + * @author kewang + * + */ +public class DBCPPlugin implements Plugin { + + @Override + public Set springClasses() { + return SetX.of(DBCPConfig.class, DBCPDataSourceBuilder.class); + } + + + +} diff --git a/micro-dbcp/src/main/java/com/aol/micro/server/spring/datasource/DBCPConfig.java b/micro-dbcp/src/main/java/com/oath/micro/server/spring/datasource/DBCPConfig.java similarity index 96% rename from micro-dbcp/src/main/java/com/aol/micro/server/spring/datasource/DBCPConfig.java rename to micro-dbcp/src/main/java/com/oath/micro/server/spring/datasource/DBCPConfig.java index 56a946a83..363a8e781 100644 --- a/micro-dbcp/src/main/java/com/aol/micro/server/spring/datasource/DBCPConfig.java +++ b/micro-dbcp/src/main/java/com/oath/micro/server/spring/datasource/DBCPConfig.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.spring.datasource; +package com.oath.micro.server.spring.datasource; import lombok.Getter; import lombok.Builder; diff --git a/micro-dbcp/src/main/java/com/aol/micro/server/spring/datasource/DBCPDataSourceBuilder.java b/micro-dbcp/src/main/java/com/oath/micro/server/spring/datasource/DBCPDataSourceBuilder.java similarity index 96% rename from micro-dbcp/src/main/java/com/aol/micro/server/spring/datasource/DBCPDataSourceBuilder.java rename to micro-dbcp/src/main/java/com/oath/micro/server/spring/datasource/DBCPDataSourceBuilder.java index 505653180..be6081857 100644 --- a/micro-dbcp/src/main/java/com/aol/micro/server/spring/datasource/DBCPDataSourceBuilder.java +++ b/micro-dbcp/src/main/java/com/oath/micro/server/spring/datasource/DBCPDataSourceBuilder.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.spring.datasource; +package com.oath.micro.server.spring.datasource; import javax.annotation.Resource; import javax.sql.DataSource; diff --git a/micro-dbcp/src/main/resources/META-INF/services/com.aol.micro.server.Plugin b/micro-dbcp/src/main/resources/META-INF/services/com.aol.micro.server.Plugin deleted file mode 100644 index d27aedb74..000000000 --- a/micro-dbcp/src/main/resources/META-INF/services/com.aol.micro.server.Plugin +++ /dev/null @@ -1 +0,0 @@ -com.aol.micro.server.spring.DBCPPlugin \ No newline at end of file diff --git a/micro-dbcp/src/main/resources/META-INF/services/com.oath.micro.server.Plugin b/micro-dbcp/src/main/resources/META-INF/services/com.oath.micro.server.Plugin new file mode 100644 index 000000000..ed9a6a54a --- /dev/null +++ b/micro-dbcp/src/main/resources/META-INF/services/com.oath.micro.server.Plugin @@ -0,0 +1 @@ +com.oath.micro.server.spring.DBCPPlugin \ No newline at end of file diff --git a/micro-dbcp/src/test/java/app/pure/jdbc/com/aol/micro/server/JdbcEntity.java b/micro-dbcp/src/test/java/app/pure/jdbc/com/aol/micro/server/JdbcEntity.java deleted file mode 100644 index 2cc20b3df..000000000 --- a/micro-dbcp/src/test/java/app/pure/jdbc/com/aol/micro/server/JdbcEntity.java +++ /dev/null @@ -1,27 +0,0 @@ -package app.pure.jdbc.com.aol.micro.server; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.Builder; - - - - -@Setter -@Getter -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class JdbcEntity implements java.io.Serializable { - - private static final long serialVersionUID = 1L; - - private Long id; - private String name; - private String value; - private int version; - - -} diff --git a/micro-dbcp/src/test/java/app/pure/jdbc/com/aol/micro/server/JdbcRunnerTest.java b/micro-dbcp/src/test/java/app/pure/jdbc/com/aol/micro/server/JdbcRunnerTest.java deleted file mode 100644 index 4bbe1dda9..000000000 --- a/micro-dbcp/src/test/java/app/pure/jdbc/com/aol/micro/server/JdbcRunnerTest.java +++ /dev/null @@ -1,49 +0,0 @@ -package app.pure.jdbc.com.aol.micro.server; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.rest.client.nio.AsyncRestClient; -import com.aol.micro.server.testing.RestAgent; - -@Microserver(properties = { "db.connection.driver", "org.hsqldb.jdbcDriver", "db.connection.url", "jdbc:hsqldb:mem:aname", "db.connection.username", - "sa", "db.connection.dialect", "org.hibernate.dialect.HSQLDialect" }) -public class JdbcRunnerTest { - - private final AsyncRestClient listClient = new AsyncRestClient(1000, 1000).withResponse(JdbcEntity.class); - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - - @Before - public void startServer() { - - server = new MicroserverApp(() -> "jdbc-app"); - server.start(); - rest.get("http://localhost:8080/jdbc-app/persistence/gen"); - - } - - @After - public void stopServer() { - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException { - - assertThat(rest.get("http://localhost:8080/jdbc-app/persistence/create"), is("ok")); - assertThat(listClient.get("http://localhost:8080/jdbc-app/persistence/get").get(), is(JdbcEntity.class)); - - } - -} diff --git a/micro-dbcp/src/test/java/app/pure/jdbc/com/aol/micro/server/PersistentResource.java b/micro-dbcp/src/test/java/app/pure/jdbc/com/aol/micro/server/PersistentResource.java deleted file mode 100644 index b826e9cd5..000000000 --- a/micro-dbcp/src/test/java/app/pure/jdbc/com/aol/micro/server/PersistentResource.java +++ /dev/null @@ -1,48 +0,0 @@ -package app.pure.jdbc.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.BeanPropertyRowMapper; - -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.spring.datasource.jdbc.SQL; - -@Rest -@Path("/persistence") -public class PersistentResource { - - private final SQL dao; - - @Autowired - public PersistentResource(SQL dao) { - - this.dao = dao; - } - @GET - @Produces("text/plain") - @Path("/gen") - public String gen() { - dao.getJdbc().execute("create table t_jdbc(id bigint,name varchar(255),value varchar(255),version int);"); - - return "ok"; - } - @GET - @Produces("text/plain") - @Path("/create") - public String createEntity() { - dao.getJdbc().update("insert into t_jdbc VALUES (1,'hello','world',1)"); - - return "ok"; - } - - @GET - @Produces("application/json") - @Path("/get") - public JdbcEntity get() { - return dao.getJdbc(). queryForObject("select * from t_jdbc", new BeanPropertyRowMapper(JdbcEntity.class)); - } - -} \ No newline at end of file diff --git a/micro-dbcp/src/test/java/app/pure/jdbc/com/oath/micro/server/JdbcEntity.java b/micro-dbcp/src/test/java/app/pure/jdbc/com/oath/micro/server/JdbcEntity.java new file mode 100644 index 000000000..c92fd662b --- /dev/null +++ b/micro-dbcp/src/test/java/app/pure/jdbc/com/oath/micro/server/JdbcEntity.java @@ -0,0 +1,27 @@ +package app.pure.jdbc.com.oath.micro.server; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.Builder; + + + + +@Setter +@Getter +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class JdbcEntity implements java.io.Serializable { + + private static final long serialVersionUID = 1L; + + private Long id; + private String name; + private String value; + private int version; + + +} diff --git a/micro-dbcp/src/test/java/app/pure/jdbc/com/oath/micro/server/JdbcRunnerTest.java b/micro-dbcp/src/test/java/app/pure/jdbc/com/oath/micro/server/JdbcRunnerTest.java new file mode 100644 index 000000000..f677ac354 --- /dev/null +++ b/micro-dbcp/src/test/java/app/pure/jdbc/com/oath/micro/server/JdbcRunnerTest.java @@ -0,0 +1,49 @@ +package app.pure.jdbc.com.oath.micro.server; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.rest.client.nio.AsyncRestClient; +import com.oath.micro.server.testing.RestAgent; + +@Microserver(properties = { "db.connection.driver", "org.hsqldb.jdbcDriver", "db.connection.url", "jdbc:hsqldb:mem:aname", "db.connection.username", + "sa", "db.connection.dialect", "org.hibernate.dialect.HSQLDialect" }) +public class JdbcRunnerTest { + + private final AsyncRestClient listClient = new AsyncRestClient(1000, 1000).withResponse(JdbcEntity.class); + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + + @Before + public void startServer() { + + server = new MicroserverApp(() -> "jdbc-app"); + server.start(); + rest.get("http://localhost:8080/jdbc-app/persistence/gen"); + + } + + @After + public void stopServer() { + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException { + + assertThat(rest.get("http://localhost:8080/jdbc-app/persistence/create"), is("ok")); + assertThat(listClient.get("http://localhost:8080/jdbc-app/persistence/get").get(), is(JdbcEntity.class)); + + } + +} diff --git a/micro-dbcp/src/test/java/app/pure/jdbc/com/oath/micro/server/PersistentResource.java b/micro-dbcp/src/test/java/app/pure/jdbc/com/oath/micro/server/PersistentResource.java new file mode 100644 index 000000000..869898590 --- /dev/null +++ b/micro-dbcp/src/test/java/app/pure/jdbc/com/oath/micro/server/PersistentResource.java @@ -0,0 +1,48 @@ +package app.pure.jdbc.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.BeanPropertyRowMapper; + +import com.oath.micro.server.auto.discovery.Rest; +import com.oath.micro.server.spring.datasource.jdbc.SQL; + +@Rest +@Path("/persistence") +public class PersistentResource { + + private final SQL dao; + + @Autowired + public PersistentResource(SQL dao) { + + this.dao = dao; + } + @GET + @Produces("text/plain") + @Path("/gen") + public String gen() { + dao.getJdbc().execute("create table t_jdbc(id bigint,name varchar(255),value varchar(255),version int);"); + + return "ok"; + } + @GET + @Produces("text/plain") + @Path("/create") + public String createEntity() { + dao.getJdbc().update("insert into t_jdbc VALUES (1,'hello','world',1)"); + + return "ok"; + } + + @GET + @Produces("application/json") + @Path("/get") + public JdbcEntity get() { + return dao.getJdbc(). queryForObject("select * from t_jdbc", new BeanPropertyRowMapper(JdbcEntity.class)); + } + +} \ No newline at end of file diff --git a/micro-dbcp/src/test/java/com/aol/micro/server/testing/RestAgent.java b/micro-dbcp/src/test/java/com/aol/micro/server/testing/RestAgent.java deleted file mode 100644 index ce204f810..000000000 --- a/micro-dbcp/src/test/java/com/aol/micro/server/testing/RestAgent.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.aol.micro.server.testing; - -import java.util.List; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.Invocation.Builder; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; - -import com.aol.micro.server.rest.jackson.JacksonUtil; - -public class RestAgent { - - - public String getJson(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.get(String.class); - - } - - public String get(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.TEXT_PLAIN); - - return request.get(String.class); - - } - - public T post(String url, Object payload,Class type) { - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); - } - - -} diff --git a/micro-dbcp/src/test/java/com/aol/micro/server/DBCPConfigTest.java b/micro-dbcp/src/test/java/com/oath/micro/server/DBCPConfigTest.java similarity index 90% rename from micro-dbcp/src/test/java/com/aol/micro/server/DBCPConfigTest.java rename to micro-dbcp/src/test/java/com/oath/micro/server/DBCPConfigTest.java index 439846bd8..cb7a4abc3 100644 --- a/micro-dbcp/src/test/java/com/aol/micro/server/DBCPConfigTest.java +++ b/micro-dbcp/src/test/java/com/oath/micro/server/DBCPConfigTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server; +package com.oath.micro.server; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; @@ -7,7 +7,7 @@ import org.junit.Before; import org.junit.Test; -import com.aol.micro.server.spring.datasource.DBCPConfig; +import com.oath.micro.server.spring.datasource.DBCPConfig; public class DBCPConfigTest { diff --git a/micro-dbcp/src/test/java/com/oath/micro/server/testing/RestAgent.java b/micro-dbcp/src/test/java/com/oath/micro/server/testing/RestAgent.java new file mode 100644 index 000000000..b2b86303e --- /dev/null +++ b/micro-dbcp/src/test/java/com/oath/micro/server/testing/RestAgent.java @@ -0,0 +1,53 @@ +package com.oath.micro.server.testing; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.Invocation.Builder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; + +import com.oath.micro.server.rest.jackson.JacksonUtil; + +public class RestAgent { + + + public String getJson(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.get(String.class); + + } + + public String get(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.TEXT_PLAIN); + + return request.get(String.class); + + } + + public T post(String url, Object payload,Class type) { + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); + } + + +} diff --git a/micro-dist-lock/src/main/java/com/aol/micro/server/dist/lock/DistLockPlugin.java b/micro-dist-lock/src/main/java/com/aol/micro/server/dist/lock/DistLockPlugin.java deleted file mode 100644 index 493a64683..000000000 --- a/micro-dist-lock/src/main/java/com/aol/micro/server/dist/lock/DistLockPlugin.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.aol.micro.server.dist.lock; - -import com.aol.micro.server.Plugin; -import com.aol.micro.server.dist.lock.rest.DistLockResource; -import cyclops.collections.immutable.PersistentSetX; -import cyclops.collections.mutable.SetX; - -import java.util.Set; - -/** - * - * @author Ke Wang - * - */ -public class DistLockPlugin implements Plugin { - @Override - public Set springClasses() { - return SetX.of(DistLockResource.class); - } - -} diff --git a/micro-dist-lock/src/main/java/com/aol/micro/server/dist/lock/DistributedLockService.java b/micro-dist-lock/src/main/java/com/aol/micro/server/dist/lock/DistributedLockService.java deleted file mode 100644 index d340083a2..000000000 --- a/micro-dist-lock/src/main/java/com/aol/micro/server/dist/lock/DistributedLockService.java +++ /dev/null @@ -1,11 +0,0 @@ - -package com.aol.micro.server.dist.lock; - - -public interface DistributedLockService { - - boolean tryLock(String key); - - boolean tryReleaseLock(String key); - -} diff --git a/micro-dist-lock/src/main/java/com/oath/micro/server/dist/lock/DistLockPlugin.java b/micro-dist-lock/src/main/java/com/oath/micro/server/dist/lock/DistLockPlugin.java new file mode 100644 index 000000000..bcf736417 --- /dev/null +++ b/micro-dist-lock/src/main/java/com/oath/micro/server/dist/lock/DistLockPlugin.java @@ -0,0 +1,20 @@ +package com.oath.micro.server.dist.lock; + +import com.oath.micro.server.Plugin; +import com.oath.micro.server.dist.lock.rest.DistLockResource; +import cyclops.collections.mutable.SetX; + +import java.util.Set; + +/** + * + * @author Ke Wang + * + */ +public class DistLockPlugin implements Plugin { + @Override + public Set springClasses() { + return SetX.of(DistLockResource.class); + } + +} diff --git a/micro-dist-lock/src/main/java/com/aol/micro/server/dist/lock/DistributedLockManager.java b/micro-dist-lock/src/main/java/com/oath/micro/server/dist/lock/DistributedLockManager.java similarity index 91% rename from micro-dist-lock/src/main/java/com/aol/micro/server/dist/lock/DistributedLockManager.java rename to micro-dist-lock/src/main/java/com/oath/micro/server/dist/lock/DistributedLockManager.java index 7e7f6e520..6a61f4566 100644 --- a/micro-dist-lock/src/main/java/com/aol/micro/server/dist/lock/DistributedLockManager.java +++ b/micro-dist-lock/src/main/java/com/oath/micro/server/dist/lock/DistributedLockManager.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.dist.lock; +package com.oath.micro.server.dist.lock; import lombok.Getter; diff --git a/micro-dist-lock/src/main/java/com/oath/micro/server/dist/lock/DistributedLockService.java b/micro-dist-lock/src/main/java/com/oath/micro/server/dist/lock/DistributedLockService.java new file mode 100644 index 000000000..2b31270eb --- /dev/null +++ b/micro-dist-lock/src/main/java/com/oath/micro/server/dist/lock/DistributedLockService.java @@ -0,0 +1,11 @@ + +package com.oath.micro.server.dist.lock; + + +public interface DistributedLockService { + + boolean tryLock(String key); + + boolean tryReleaseLock(String key); + +} diff --git a/micro-dist-lock/src/main/java/com/aol/micro/server/dist/lock/rest/DistLockResource.java b/micro-dist-lock/src/main/java/com/oath/micro/server/dist/lock/rest/DistLockResource.java similarity index 87% rename from micro-dist-lock/src/main/java/com/aol/micro/server/dist/lock/rest/DistLockResource.java rename to micro-dist-lock/src/main/java/com/oath/micro/server/dist/lock/rest/DistLockResource.java index 71027084f..b0a018bc8 100644 --- a/micro-dist-lock/src/main/java/com/aol/micro/server/dist/lock/rest/DistLockResource.java +++ b/micro-dist-lock/src/main/java/com/oath/micro/server/dist/lock/rest/DistLockResource.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.dist.lock.rest; +package com.oath.micro.server.dist.lock.rest; import java.util.HashMap; import java.util.List; @@ -14,8 +14,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import com.aol.micro.server.auto.discovery.SingletonRestResource; -import com.aol.micro.server.dist.lock.DistributedLockManager; +import com.oath.micro.server.auto.discovery.SingletonRestResource; +import com.oath.micro.server.dist.lock.DistributedLockManager; @Component @Path("/lock-owner") diff --git a/micro-dist-lock/src/main/resources/META-INF/services/com.aol.micro.server.Plugin b/micro-dist-lock/src/main/resources/META-INF/services/com.aol.micro.server.Plugin deleted file mode 100644 index 73ac019d2..000000000 --- a/micro-dist-lock/src/main/resources/META-INF/services/com.aol.micro.server.Plugin +++ /dev/null @@ -1 +0,0 @@ -com.aol.micro.server.dist.lock.DistLockPlugin \ No newline at end of file diff --git a/micro-dist-lock/src/main/resources/META-INF/services/com.oath.micro.server.Plugin b/micro-dist-lock/src/main/resources/META-INF/services/com.oath.micro.server.Plugin new file mode 100644 index 000000000..42e5b06c3 --- /dev/null +++ b/micro-dist-lock/src/main/resources/META-INF/services/com.oath.micro.server.Plugin @@ -0,0 +1 @@ +com.oath.micro.server.dist.lock.DistLockPlugin \ No newline at end of file diff --git a/micro-dist-lock/src/test/java/app/com/aol/micro/server/dist/lock/rest/ConfigureDistLock.java b/micro-dist-lock/src/test/java/app/com/aol/micro/server/dist/lock/rest/ConfigureDistLock.java deleted file mode 100644 index f097f8350..000000000 --- a/micro-dist-lock/src/test/java/app/com/aol/micro/server/dist/lock/rest/ConfigureDistLock.java +++ /dev/null @@ -1,21 +0,0 @@ -package app.com.aol.micro.server.dist.lock.rest; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import com.aol.micro.server.dist.lock.DistributedLockManager; -import com.aol.micro.server.dist.lock.DistributedLockService; - -@Configuration -public class ConfigureDistLock { - - @Autowired - private DistributedLockService distributedLockService; - - @Bean - public DistributedLockManager manager() { - return new DistributedLockManager( - distributedLockService, "dummy-key"); - } -} diff --git a/micro-dist-lock/src/test/java/app/com/aol/micro/server/dist/lock/rest/DummyLock.java b/micro-dist-lock/src/test/java/app/com/aol/micro/server/dist/lock/rest/DummyLock.java deleted file mode 100644 index 3421d34c0..000000000 --- a/micro-dist-lock/src/test/java/app/com/aol/micro/server/dist/lock/rest/DummyLock.java +++ /dev/null @@ -1,23 +0,0 @@ -package app.com.aol.micro.server.dist.lock.rest; - -import org.springframework.stereotype.Component; - -import com.aol.micro.server.dist.lock.DistributedLockService; - -@Component -public class DummyLock implements DistributedLockService { - - @Override - public boolean tryLock(String key) { - if (key.equals("dummy-key")) { - return true; - } - return false; - } - - @Override - public boolean tryReleaseLock(String key) { - return false; - } - -} diff --git a/micro-dist-lock/src/test/java/app/com/oath/micro/server/dist/lock/rest/ConfigureDistLock.java b/micro-dist-lock/src/test/java/app/com/oath/micro/server/dist/lock/rest/ConfigureDistLock.java new file mode 100644 index 000000000..88aed2da8 --- /dev/null +++ b/micro-dist-lock/src/test/java/app/com/oath/micro/server/dist/lock/rest/ConfigureDistLock.java @@ -0,0 +1,21 @@ +package app.com.oath.micro.server.dist.lock.rest; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import com.oath.micro.server.dist.lock.DistributedLockManager; +import com.oath.micro.server.dist.lock.DistributedLockService; + +@Configuration +public class ConfigureDistLock { + + @Autowired + private DistributedLockService distributedLockService; + + @Bean + public DistributedLockManager manager() { + return new DistributedLockManager( + distributedLockService, "dummy-key"); + } +} diff --git a/micro-dist-lock/src/test/java/app/com/aol/micro/server/dist/lock/rest/DistLockRunnerTest.java b/micro-dist-lock/src/test/java/app/com/oath/micro/server/dist/lock/rest/DistLockRunnerTest.java similarity index 80% rename from micro-dist-lock/src/test/java/app/com/aol/micro/server/dist/lock/rest/DistLockRunnerTest.java rename to micro-dist-lock/src/test/java/app/com/oath/micro/server/dist/lock/rest/DistLockRunnerTest.java index b702d20fe..6352f513a 100644 --- a/micro-dist-lock/src/test/java/app/com/aol/micro/server/dist/lock/rest/DistLockRunnerTest.java +++ b/micro-dist-lock/src/test/java/app/com/oath/micro/server/dist/lock/rest/DistLockRunnerTest.java @@ -1,4 +1,4 @@ -package app.com.aol.micro.server.dist.lock.rest; +package app.com.oath.micro.server.dist.lock.rest; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; @@ -7,9 +7,9 @@ import org.junit.Before; import org.junit.Test; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.testing.RestAgent; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.testing.RestAgent; @Microserver public class DistLockRunnerTest { diff --git a/micro-dist-lock/src/test/java/app/com/oath/micro/server/dist/lock/rest/DummyLock.java b/micro-dist-lock/src/test/java/app/com/oath/micro/server/dist/lock/rest/DummyLock.java new file mode 100644 index 000000000..f70766227 --- /dev/null +++ b/micro-dist-lock/src/test/java/app/com/oath/micro/server/dist/lock/rest/DummyLock.java @@ -0,0 +1,23 @@ +package app.com.oath.micro.server.dist.lock.rest; + +import org.springframework.stereotype.Component; + +import com.oath.micro.server.dist.lock.DistributedLockService; + +@Component +public class DummyLock implements DistributedLockService { + + @Override + public boolean tryLock(String key) { + if (key.equals("dummy-key")) { + return true; + } + return false; + } + + @Override + public boolean tryReleaseLock(String key) { + return false; + } + +} diff --git a/micro-dist-lock/src/test/java/com/aol/micro/server/testing/RestAgent.java b/micro-dist-lock/src/test/java/com/aol/micro/server/testing/RestAgent.java deleted file mode 100644 index ce204f810..000000000 --- a/micro-dist-lock/src/test/java/com/aol/micro/server/testing/RestAgent.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.aol.micro.server.testing; - -import java.util.List; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.Invocation.Builder; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; - -import com.aol.micro.server.rest.jackson.JacksonUtil; - -public class RestAgent { - - - public String getJson(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.get(String.class); - - } - - public String get(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.TEXT_PLAIN); - - return request.get(String.class); - - } - - public T post(String url, Object payload,Class type) { - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); - } - - -} diff --git a/micro-dist-lock/src/test/java/com/oath/micro/server/testing/RestAgent.java b/micro-dist-lock/src/test/java/com/oath/micro/server/testing/RestAgent.java new file mode 100644 index 000000000..b2b86303e --- /dev/null +++ b/micro-dist-lock/src/test/java/com/oath/micro/server/testing/RestAgent.java @@ -0,0 +1,53 @@ +package com.oath.micro.server.testing; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.Invocation.Builder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; + +import com.oath.micro.server.rest.jackson.JacksonUtil; + +public class RestAgent { + + + public String getJson(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.get(String.class); + + } + + public String get(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.TEXT_PLAIN); + + return request.get(String.class); + + } + + public T post(String url, Object payload,Class type) { + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); + } + + +} diff --git a/micro-elasticache/src/main/java/com/aol/micro/server/elasticache/ElasticachePlugin.java b/micro-elasticache/src/main/java/com/aol/micro/server/elasticache/ElasticachePlugin.java deleted file mode 100644 index acff72e14..000000000 --- a/micro-elasticache/src/main/java/com/aol/micro/server/elasticache/ElasticachePlugin.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.aol.micro.server.elasticache; - -import com.aol.micro.server.Plugin; -import cyclops.collections.immutable.PersistentSetX; -import cyclops.collections.mutable.SetX; - -import java.util.Set; - -public class ElasticachePlugin implements Plugin { - - @Override - public Set springClasses() { - return SetX.of(ConfigureElasticache.class); - } -} \ No newline at end of file diff --git a/micro-elasticache/src/main/java/com/aol/micro/server/elasticache/ConfigureElasticache.java b/micro-elasticache/src/main/java/com/oath/micro/server/elasticache/ConfigureElasticache.java similarity index 87% rename from micro-elasticache/src/main/java/com/aol/micro/server/elasticache/ConfigureElasticache.java rename to micro-elasticache/src/main/java/com/oath/micro/server/elasticache/ConfigureElasticache.java index f8076bb1a..3ae3dd345 100644 --- a/micro-elasticache/src/main/java/com/aol/micro/server/elasticache/ConfigureElasticache.java +++ b/micro-elasticache/src/main/java/com/oath/micro/server/elasticache/ConfigureElasticache.java @@ -1,29 +1,21 @@ -package com.aol.micro.server.elasticache; +package com.oath.micro.server.elasticache; import lombok.extern.slf4j.Slf4j; -import net.spy.memcached.*; import java.io.IOException; import java.net.URISyntaxException; -import java.util.ArrayList; -import net.spy.memcached.auth.AuthDescriptor; -import net.spy.memcached.auth.PlainCallbackHandler; import net.spy.memcached.MemcachedClient; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.util.StringUtils; import java.net.InetSocketAddress; -import java.util.List; -import java.util.Optional; - @Slf4j @Configuration public class ConfigureElasticache { diff --git a/micro-elasticache/src/main/java/com/aol/micro/server/elasticache/DistributedCacheManager.java b/micro-elasticache/src/main/java/com/oath/micro/server/elasticache/DistributedCacheManager.java similarity index 85% rename from micro-elasticache/src/main/java/com/aol/micro/server/elasticache/DistributedCacheManager.java rename to micro-elasticache/src/main/java/com/oath/micro/server/elasticache/DistributedCacheManager.java index b0669ff8b..28c1eac8f 100644 --- a/micro-elasticache/src/main/java/com/aol/micro/server/elasticache/DistributedCacheManager.java +++ b/micro-elasticache/src/main/java/com/oath/micro/server/elasticache/DistributedCacheManager.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.elasticache; +package com.oath.micro.server.elasticache; import java.util.Optional; public interface DistributedCacheManager { diff --git a/micro-elasticache/src/main/java/com/oath/micro/server/elasticache/ElasticachePlugin.java b/micro-elasticache/src/main/java/com/oath/micro/server/elasticache/ElasticachePlugin.java new file mode 100644 index 000000000..269a4bb14 --- /dev/null +++ b/micro-elasticache/src/main/java/com/oath/micro/server/elasticache/ElasticachePlugin.java @@ -0,0 +1,14 @@ +package com.oath.micro.server.elasticache; + +import com.oath.micro.server.Plugin; +import cyclops.collections.mutable.SetX; + +import java.util.Set; + +public class ElasticachePlugin implements Plugin { + + @Override + public Set springClasses() { + return SetX.of(ConfigureElasticache.class); + } +} \ No newline at end of file diff --git a/micro-elasticache/src/main/java/com/aol/micro/server/elasticache/TransientElasticacheDataConnection.java b/micro-elasticache/src/main/java/com/oath/micro/server/elasticache/TransientElasticacheDataConnection.java similarity index 96% rename from micro-elasticache/src/main/java/com/aol/micro/server/elasticache/TransientElasticacheDataConnection.java rename to micro-elasticache/src/main/java/com/oath/micro/server/elasticache/TransientElasticacheDataConnection.java index 5f7973892..372770a1d 100644 --- a/micro-elasticache/src/main/java/com/aol/micro/server/elasticache/TransientElasticacheDataConnection.java +++ b/micro-elasticache/src/main/java/com/oath/micro/server/elasticache/TransientElasticacheDataConnection.java @@ -1,10 +1,9 @@ -package com.aol.micro.server.elasticache; +package com.oath.micro.server.elasticache; import lombok.extern.slf4j.Slf4j; import java.util.Optional; import net.spy.memcached.MemcachedClient; -import lombok.extern.slf4j.Slf4j; @Slf4j diff --git a/micro-elasticache/src/main/resources/META-INF/services/com.aol.micro.server.Plugin b/micro-elasticache/src/main/resources/META-INF/services/com.aol.micro.server.Plugin deleted file mode 100644 index 496fed9c2..000000000 --- a/micro-elasticache/src/main/resources/META-INF/services/com.aol.micro.server.Plugin +++ /dev/null @@ -1 +0,0 @@ -com.aol.micro.server.elasticache.ElasticachePlugin \ No newline at end of file diff --git a/micro-elasticache/src/main/resources/META-INF/services/com.oath.micro.server.Plugin b/micro-elasticache/src/main/resources/META-INF/services/com.oath.micro.server.Plugin new file mode 100644 index 000000000..79998ec6f --- /dev/null +++ b/micro-elasticache/src/main/resources/META-INF/services/com.oath.micro.server.Plugin @@ -0,0 +1 @@ +com.oath.micro.server.elasticache.ElasticachePlugin \ No newline at end of file diff --git a/micro-elasticache/src/test/java/com/aol/micros/server/elasticache/TransientElasticacheDataConnectionTest.java b/micro-elasticache/src/test/java/com/oath/micros/server/elasticache/TransientElasticacheDataConnectionTest.java similarity index 94% rename from micro-elasticache/src/test/java/com/aol/micros/server/elasticache/TransientElasticacheDataConnectionTest.java rename to micro-elasticache/src/test/java/com/oath/micros/server/elasticache/TransientElasticacheDataConnectionTest.java index fa02fcd18..fa07d2262 100644 --- a/micro-elasticache/src/test/java/com/aol/micros/server/elasticache/TransientElasticacheDataConnectionTest.java +++ b/micro-elasticache/src/test/java/com/oath/micros/server/elasticache/TransientElasticacheDataConnectionTest.java @@ -1,9 +1,9 @@ -package com.aol.micros.server.elasticache; +package com.oath.micros.server.elasticache; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.stub; import static org.junit.Assert.assertEquals; -import com.aol.micro.server.elasticache.TransientElasticacheDataConnection; +import com.oath.micro.server.elasticache.TransientElasticacheDataConnection; import net.spy.memcached.internal.OperationFuture; import org.junit.Before; import org.junit.Test; diff --git a/micro-error-codes/src/main/java/com/aol/micro/server/errors/Severity.java b/micro-error-codes/src/main/java/com/aol/micro/server/errors/Severity.java deleted file mode 100644 index fa83a4a12..000000000 --- a/micro-error-codes/src/main/java/com/aol/micro/server/errors/Severity.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.aol.micro.server.errors; - -public enum Severity { - LOW, MEDIUM, HIGH, CRITICAL, FATAL -} diff --git a/micro-error-codes/src/main/java/com/aol/micro/server/plugin/ErrorsPlugin.java b/micro-error-codes/src/main/java/com/aol/micro/server/plugin/ErrorsPlugin.java deleted file mode 100644 index bfd7115fb..000000000 --- a/micro-error-codes/src/main/java/com/aol/micro/server/plugin/ErrorsPlugin.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.aol.micro.server.plugin; - -import com.aol.micro.server.Plugin; -import com.aol.micro.server.health.HealthCheck; -import com.aol.micro.server.health.HealthChecker; -import com.aol.micro.server.rest.HealthCheckResource; -import cyclops.collections.immutable.PersistentSetX; -import cyclops.collections.mutable.SetX; - -import java.util.Set; - -public class ErrorsPlugin implements Plugin { - - @Override - public Set springClasses() { - return SetX.of(HealthCheckResource.class, HealthChecker.class, HealthCheck.class); - } - -} diff --git a/micro-error-codes/src/main/java/com/aol/micro/server/errors/BaseException.java b/micro-error-codes/src/main/java/com/oath/micro/server/errors/BaseException.java similarity index 88% rename from micro-error-codes/src/main/java/com/aol/micro/server/errors/BaseException.java rename to micro-error-codes/src/main/java/com/oath/micro/server/errors/BaseException.java index f91c209d4..23cbef50c 100644 --- a/micro-error-codes/src/main/java/com/aol/micro/server/errors/BaseException.java +++ b/micro-error-codes/src/main/java/com/oath/micro/server/errors/BaseException.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.errors; +package com.oath.micro.server.errors; import lombok.Getter; diff --git a/micro-error-codes/src/main/java/com/aol/micro/server/errors/ErrorBus.java b/micro-error-codes/src/main/java/com/oath/micro/server/errors/ErrorBus.java similarity index 88% rename from micro-error-codes/src/main/java/com/aol/micro/server/errors/ErrorBus.java rename to micro-error-codes/src/main/java/com/oath/micro/server/errors/ErrorBus.java index 776c7748d..642f254ab 100644 --- a/micro-error-codes/src/main/java/com/aol/micro/server/errors/ErrorBus.java +++ b/micro-error-codes/src/main/java/com/oath/micro/server/errors/ErrorBus.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.errors; +package com.oath.micro.server.errors; import com.google.common.eventbus.EventBus; diff --git a/micro-error-codes/src/main/java/com/aol/micro/server/errors/ErrorCode.java b/micro-error-codes/src/main/java/com/oath/micro/server/errors/ErrorCode.java similarity index 98% rename from micro-error-codes/src/main/java/com/aol/micro/server/errors/ErrorCode.java rename to micro-error-codes/src/main/java/com/oath/micro/server/errors/ErrorCode.java index 4471cc451..7b5f43eff 100644 --- a/micro-error-codes/src/main/java/com/aol/micro/server/errors/ErrorCode.java +++ b/micro-error-codes/src/main/java/com/oath/micro/server/errors/ErrorCode.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.errors; +package com.oath.micro.server.errors; import java.text.MessageFormat; diff --git a/micro-error-codes/src/main/java/com/aol/micro/server/errors/FormattedErrorCode.java b/micro-error-codes/src/main/java/com/oath/micro/server/errors/FormattedErrorCode.java similarity index 84% rename from micro-error-codes/src/main/java/com/aol/micro/server/errors/FormattedErrorCode.java rename to micro-error-codes/src/main/java/com/oath/micro/server/errors/FormattedErrorCode.java index 42d652a81..4e51c1777 100644 --- a/micro-error-codes/src/main/java/com/aol/micro/server/errors/FormattedErrorCode.java +++ b/micro-error-codes/src/main/java/com/oath/micro/server/errors/FormattedErrorCode.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.errors; +package com.oath.micro.server.errors; import lombok.AccessLevel; import lombok.AllArgsConstructor; diff --git a/micro-error-codes/src/main/java/com/aol/micro/server/errors/InvalidStateException.java b/micro-error-codes/src/main/java/com/oath/micro/server/errors/InvalidStateException.java similarity index 87% rename from micro-error-codes/src/main/java/com/aol/micro/server/errors/InvalidStateException.java rename to micro-error-codes/src/main/java/com/oath/micro/server/errors/InvalidStateException.java index a4fa6e613..94118889b 100644 --- a/micro-error-codes/src/main/java/com/aol/micro/server/errors/InvalidStateException.java +++ b/micro-error-codes/src/main/java/com/oath/micro/server/errors/InvalidStateException.java @@ -1,6 +1,6 @@ -package com.aol.micro.server.errors; +package com.oath.micro.server.errors; -import com.aol.micro.server.health.ErrorEvent; +import com.oath.micro.server.health.ErrorEvent; public class InvalidStateException extends BaseException { diff --git a/micro-error-codes/src/main/java/com/oath/micro/server/errors/Severity.java b/micro-error-codes/src/main/java/com/oath/micro/server/errors/Severity.java new file mode 100644 index 000000000..d9b508ee3 --- /dev/null +++ b/micro-error-codes/src/main/java/com/oath/micro/server/errors/Severity.java @@ -0,0 +1,5 @@ +package com.oath.micro.server.errors; + +public enum Severity { + LOW, MEDIUM, HIGH, CRITICAL, FATAL +} diff --git a/micro-error-codes/src/main/java/com/aol/micro/server/health/ErrorEvent.java b/micro-error-codes/src/main/java/com/oath/micro/server/health/ErrorEvent.java similarity index 89% rename from micro-error-codes/src/main/java/com/aol/micro/server/health/ErrorEvent.java rename to micro-error-codes/src/main/java/com/oath/micro/server/health/ErrorEvent.java index 2d22bcc01..7a6e7ce17 100644 --- a/micro-error-codes/src/main/java/com/aol/micro/server/health/ErrorEvent.java +++ b/micro-error-codes/src/main/java/com/oath/micro/server/health/ErrorEvent.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.health; +package com.oath.micro.server.health; import java.io.Serializable; import java.text.SimpleDateFormat; @@ -12,9 +12,9 @@ import javax.xml.bind.annotation.XmlTransient; import javax.xml.bind.annotation.XmlType; -import com.aol.micro.server.errors.BaseException; -import com.aol.micro.server.errors.ErrorCode; -import com.aol.micro.server.errors.Severity; +import com.oath.micro.server.errors.BaseException; +import com.oath.micro.server.errors.ErrorCode; +import com.oath.micro.server.errors.Severity; import lombok.Getter; diff --git a/micro-error-codes/src/main/java/com/aol/micro/server/health/HealthCheck.java b/micro-error-codes/src/main/java/com/oath/micro/server/health/HealthCheck.java similarity index 92% rename from micro-error-codes/src/main/java/com/aol/micro/server/health/HealthCheck.java rename to micro-error-codes/src/main/java/com/oath/micro/server/health/HealthCheck.java index 0261bd2b1..a20ff53c7 100644 --- a/micro-error-codes/src/main/java/com/aol/micro/server/health/HealthCheck.java +++ b/micro-error-codes/src/main/java/com/oath/micro/server/health/HealthCheck.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.health; +package com.oath.micro.server.health; import java.util.concurrent.ConcurrentLinkedQueue; @@ -10,9 +10,9 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; -import com.aol.micro.server.HealthStatusChecker; -import com.aol.micro.server.errors.ErrorBus; -import com.aol.micro.server.health.HealthStatus.State; +import com.oath.micro.server.HealthStatusChecker; +import com.oath.micro.server.errors.ErrorBus; +import com.oath.micro.server.health.HealthStatus.State; import com.google.common.eventbus.EventBus; import com.google.common.eventbus.Subscribe; diff --git a/micro-error-codes/src/main/java/com/aol/micro/server/health/HealthChecker.java b/micro-error-codes/src/main/java/com/oath/micro/server/health/HealthChecker.java similarity index 97% rename from micro-error-codes/src/main/java/com/aol/micro/server/health/HealthChecker.java rename to micro-error-codes/src/main/java/com/oath/micro/server/health/HealthChecker.java index b4995c119..7cc5e202a 100644 --- a/micro-error-codes/src/main/java/com/aol/micro/server/health/HealthChecker.java +++ b/micro-error-codes/src/main/java/com/oath/micro/server/health/HealthChecker.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.health; +package com.oath.micro.server.health; import java.util.Queue; diff --git a/micro-error-codes/src/main/java/com/aol/micro/server/health/HealthStatus.java b/micro-error-codes/src/main/java/com/oath/micro/server/health/HealthStatus.java similarity index 96% rename from micro-error-codes/src/main/java/com/aol/micro/server/health/HealthStatus.java rename to micro-error-codes/src/main/java/com/oath/micro/server/health/HealthStatus.java index 18fe3cf2c..11ca0c87c 100644 --- a/micro-error-codes/src/main/java/com/aol/micro/server/health/HealthStatus.java +++ b/micro-error-codes/src/main/java/com/oath/micro/server/health/HealthStatus.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.health; +package com.oath.micro.server.health; import java.io.Serializable; import java.util.Queue; diff --git a/micro-error-codes/src/main/java/com/oath/micro/server/plugin/ErrorsPlugin.java b/micro-error-codes/src/main/java/com/oath/micro/server/plugin/ErrorsPlugin.java new file mode 100644 index 000000000..19185a3d4 --- /dev/null +++ b/micro-error-codes/src/main/java/com/oath/micro/server/plugin/ErrorsPlugin.java @@ -0,0 +1,18 @@ +package com.oath.micro.server.plugin; + +import com.oath.micro.server.Plugin; +import com.oath.micro.server.health.HealthCheck; +import com.oath.micro.server.health.HealthChecker; +import com.oath.micro.server.rest.HealthCheckResource; +import cyclops.collections.mutable.SetX; + +import java.util.Set; + +public class ErrorsPlugin implements Plugin { + + @Override + public Set springClasses() { + return SetX.of(HealthCheckResource.class, HealthChecker.class, HealthCheck.class); + } + +} diff --git a/micro-error-codes/src/main/java/com/aol/micro/server/rest/HealthCheckResource.java b/micro-error-codes/src/main/java/com/oath/micro/server/rest/HealthCheckResource.java similarity index 87% rename from micro-error-codes/src/main/java/com/aol/micro/server/rest/HealthCheckResource.java rename to micro-error-codes/src/main/java/com/oath/micro/server/rest/HealthCheckResource.java index af0636ed2..113aaa8d0 100644 --- a/micro-error-codes/src/main/java/com/aol/micro/server/rest/HealthCheckResource.java +++ b/micro-error-codes/src/main/java/com/oath/micro/server/rest/HealthCheckResource.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.rest; +package com.oath.micro.server.rest; import java.util.Map; @@ -16,10 +16,10 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; -import com.aol.micro.server.auto.discovery.CommonRestResource; -import com.aol.micro.server.auto.discovery.SingletonRestResource; -import com.aol.micro.server.health.HealthCheck; -import com.aol.micro.server.utility.HashMapBuilder; +import com.oath.micro.server.auto.discovery.CommonRestResource; +import com.oath.micro.server.auto.discovery.SingletonRestResource; +import com.oath.micro.server.health.HealthCheck; +import com.oath.micro.server.utility.HashMapBuilder; @Path("/system-errors") @Component diff --git a/micro-error-codes/src/main/resources/META-INF/services/com.aol.micro.server.Plugin b/micro-error-codes/src/main/resources/META-INF/services/com.aol.micro.server.Plugin deleted file mode 100644 index 9405cde87..000000000 --- a/micro-error-codes/src/main/resources/META-INF/services/com.aol.micro.server.Plugin +++ /dev/null @@ -1 +0,0 @@ -com.aol.micro.server.plugin.ErrorsPlugin \ No newline at end of file diff --git a/micro-error-codes/src/main/resources/META-INF/services/com.oath.micro.server.Plugin b/micro-error-codes/src/main/resources/META-INF/services/com.oath.micro.server.Plugin new file mode 100644 index 000000000..a31f0780d --- /dev/null +++ b/micro-error-codes/src/main/resources/META-INF/services/com.oath.micro.server.Plugin @@ -0,0 +1 @@ +com.oath.micro.server.plugin.ErrorsPlugin \ No newline at end of file diff --git a/micro-error-codes/src/test/java/app/errors/com/aol/micro/server/Errors.java b/micro-error-codes/src/test/java/app/errors/com/aol/micro/server/Errors.java deleted file mode 100644 index 2e6ebdf44..000000000 --- a/micro-error-codes/src/test/java/app/errors/com/aol/micro/server/Errors.java +++ /dev/null @@ -1,9 +0,0 @@ -package app.errors.com.aol.micro.server; - -import com.aol.micro.server.errors.ErrorCode; -import com.aol.micro.server.errors.Severity; - -public interface Errors { - public final static ErrorCode QUERY_FAILURE = ErrorCode.error(1, "something {0} bad happened", Severity.CRITICAL); - public final static ErrorCode SYSTEM_FAILURE = ErrorCode.error(2, "something {0} really bad", Severity.FATAL); -} diff --git a/micro-error-codes/src/test/java/app/errors/com/aol/micro/server/SingleClassTest.java b/micro-error-codes/src/test/java/app/errors/com/aol/micro/server/SingleClassTest.java deleted file mode 100644 index d827c4ced..000000000 --- a/micro-error-codes/src/test/java/app/errors/com/aol/micro/server/SingleClassTest.java +++ /dev/null @@ -1,90 +0,0 @@ -package app.errors.com.aol.micro.server; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.RestResource; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.errors.InvalidStateException; -import com.aol.micro.server.health.HealthStatus; -import com.aol.micro.server.testing.RestAgent; - -@Microserver -@Path("/single") -public class SingleClassTest implements RestResource { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - - @Before - public void startServer() { - - server = new MicroserverApp( - SingleClassTest.class, () -> "simple-app"); - server.start(); - - } - - @After - public void stopServer() { - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException { - - rest.get("http://localhost:8080/simple-app/single/error"); - - assertThat(rest.get("http://localhost:8080/simple-app/system-errors/status"), - is(HealthStatus.State.Errors.name())); - assertThat(rest.getJson("http://localhost:8080/simple-app/system-errors/errors"), - containsString("formatted-date")); - - rest.get("http://localhost:8080/simple-app/single/fatal"); - - System.out.println(rest.getJson("http://localhost:8080/simple-app/system-errors/errors")); - assertThat(rest.get("http://localhost:8080/simple-app/system-errors/status"), - is(HealthStatus.State.Fatal.name())); - - } - - @GET - @Produces("text/plain") - @Path("/error") - public String error() { - try { - throw new InvalidStateException( - Errors.QUERY_FAILURE.format("*eek*")); - } catch (Exception e) { - e.printStackTrace(); - } - return "error"; - } - - @GET - @Produces("text/plain") - @Path("/fatal") - public String fatal() { - try { - throw new InvalidStateException( - Errors.SYSTEM_FAILURE.format("*eek*")); - } catch (Exception e) { - e.printStackTrace(); - } - return "unrecoverable fatal error"; - } - -} \ No newline at end of file diff --git a/micro-error-codes/src/test/java/app/errors/com/oath/micro/server/Errors.java b/micro-error-codes/src/test/java/app/errors/com/oath/micro/server/Errors.java new file mode 100644 index 000000000..b7d499f99 --- /dev/null +++ b/micro-error-codes/src/test/java/app/errors/com/oath/micro/server/Errors.java @@ -0,0 +1,9 @@ +package app.errors.com.oath.micro.server; + +import com.oath.micro.server.errors.ErrorCode; +import com.oath.micro.server.errors.Severity; + +public interface Errors { + public final static ErrorCode QUERY_FAILURE = ErrorCode.error(1, "something {0} bad happened", Severity.CRITICAL); + public final static ErrorCode SYSTEM_FAILURE = ErrorCode.error(2, "something {0} really bad", Severity.FATAL); +} diff --git a/micro-error-codes/src/test/java/app/errors/com/oath/micro/server/SingleClassTest.java b/micro-error-codes/src/test/java/app/errors/com/oath/micro/server/SingleClassTest.java new file mode 100644 index 000000000..2abc7346f --- /dev/null +++ b/micro-error-codes/src/test/java/app/errors/com/oath/micro/server/SingleClassTest.java @@ -0,0 +1,90 @@ +package app.errors.com.oath.micro.server; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.auto.discovery.RestResource; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.errors.InvalidStateException; +import com.oath.micro.server.health.HealthStatus; +import com.oath.micro.server.testing.RestAgent; + +@Microserver +@Path("/single") +public class SingleClassTest implements RestResource { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + + @Before + public void startServer() { + + server = new MicroserverApp( + SingleClassTest.class, () -> "simple-app"); + server.start(); + + } + + @After + public void stopServer() { + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException { + + rest.get("http://localhost:8080/simple-app/single/error"); + + assertThat(rest.get("http://localhost:8080/simple-app/system-errors/status"), + is(HealthStatus.State.Errors.name())); + assertThat(rest.getJson("http://localhost:8080/simple-app/system-errors/errors"), + containsString("formatted-date")); + + rest.get("http://localhost:8080/simple-app/single/fatal"); + + System.out.println(rest.getJson("http://localhost:8080/simple-app/system-errors/errors")); + assertThat(rest.get("http://localhost:8080/simple-app/system-errors/status"), + is(HealthStatus.State.Fatal.name())); + + } + + @GET + @Produces("text/plain") + @Path("/error") + public String error() { + try { + throw new InvalidStateException( + Errors.QUERY_FAILURE.format("*eek*")); + } catch (Exception e) { + e.printStackTrace(); + } + return "error"; + } + + @GET + @Produces("text/plain") + @Path("/fatal") + public String fatal() { + try { + throw new InvalidStateException( + Errors.SYSTEM_FAILURE.format("*eek*")); + } catch (Exception e) { + e.printStackTrace(); + } + return "unrecoverable fatal error"; + } + +} \ No newline at end of file diff --git a/micro-error-codes/src/test/java/com/aol/micro/server/testing/RestAgent.java b/micro-error-codes/src/test/java/com/aol/micro/server/testing/RestAgent.java deleted file mode 100644 index ce204f810..000000000 --- a/micro-error-codes/src/test/java/com/aol/micro/server/testing/RestAgent.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.aol.micro.server.testing; - -import java.util.List; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.Invocation.Builder; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; - -import com.aol.micro.server.rest.jackson.JacksonUtil; - -public class RestAgent { - - - public String getJson(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.get(String.class); - - } - - public String get(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.TEXT_PLAIN); - - return request.get(String.class); - - } - - public T post(String url, Object payload,Class type) { - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); - } - - -} diff --git a/micro-error-codes/src/test/java/com/aol/micro/server/common/exceptions/ErrorBusTest.java b/micro-error-codes/src/test/java/com/oath/micro/server/common/exceptions/ErrorBusTest.java similarity index 83% rename from micro-error-codes/src/test/java/com/aol/micro/server/common/exceptions/ErrorBusTest.java rename to micro-error-codes/src/test/java/com/oath/micro/server/common/exceptions/ErrorBusTest.java index faa12882c..14e16c159 100644 --- a/micro-error-codes/src/test/java/com/aol/micro/server/common/exceptions/ErrorBusTest.java +++ b/micro-error-codes/src/test/java/com/oath/micro/server/common/exceptions/ErrorBusTest.java @@ -1,11 +1,11 @@ -package com.aol.micro.server.common.exceptions; +package com.oath.micro.server.common.exceptions; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import org.junit.Test; -import com.aol.micro.server.errors.ErrorBus; +import com.oath.micro.server.errors.ErrorBus; import com.google.common.eventbus.EventBus; public class ErrorBusTest { diff --git a/micro-error-codes/src/test/java/com/aol/micro/server/common/exceptions/InvalidStateExceptionTest.java b/micro-error-codes/src/test/java/com/oath/micro/server/common/exceptions/InvalidStateExceptionTest.java similarity index 75% rename from micro-error-codes/src/test/java/com/aol/micro/server/common/exceptions/InvalidStateExceptionTest.java rename to micro-error-codes/src/test/java/com/oath/micro/server/common/exceptions/InvalidStateExceptionTest.java index ce708db1d..977e5cef3 100644 --- a/micro-error-codes/src/test/java/com/aol/micro/server/common/exceptions/InvalidStateExceptionTest.java +++ b/micro-error-codes/src/test/java/com/oath/micro/server/common/exceptions/InvalidStateExceptionTest.java @@ -1,17 +1,17 @@ -package com.aol.micro.server.common.exceptions; +package com.oath.micro.server.common.exceptions; import static org.junit.Assert.assertTrue; import org.junit.Before; import org.junit.Test; -import com.aol.micro.server.errors.ErrorBus; -import com.aol.micro.server.errors.InvalidStateException; -import com.aol.micro.server.health.ErrorEvent; +import com.oath.micro.server.errors.ErrorBus; +import com.oath.micro.server.errors.InvalidStateException; +import com.oath.micro.server.health.ErrorEvent; import com.google.common.eventbus.EventBus; import com.google.common.eventbus.Subscribe; -import app.errors.com.aol.micro.server.Errors; +import app.errors.com.oath.micro.server.Errors; public class InvalidStateExceptionTest { diff --git a/micro-error-codes/src/test/java/com/aol/micro/server/health/HealthCheckTest.java b/micro-error-codes/src/test/java/com/oath/micro/server/health/HealthCheckTest.java similarity index 98% rename from micro-error-codes/src/test/java/com/aol/micro/server/health/HealthCheckTest.java rename to micro-error-codes/src/test/java/com/oath/micro/server/health/HealthCheckTest.java index fe2716fbd..46554b52a 100644 --- a/micro-error-codes/src/test/java/com/aol/micro/server/health/HealthCheckTest.java +++ b/micro-error-codes/src/test/java/com/oath/micro/server/health/HealthCheckTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.health; +package com.oath.micro.server.health; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; diff --git a/micro-error-codes/src/test/java/com/oath/micro/server/testing/RestAgent.java b/micro-error-codes/src/test/java/com/oath/micro/server/testing/RestAgent.java new file mode 100644 index 000000000..b2b86303e --- /dev/null +++ b/micro-error-codes/src/test/java/com/oath/micro/server/testing/RestAgent.java @@ -0,0 +1,53 @@ +package com.oath.micro.server.testing; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.Invocation.Builder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; + +import com.oath.micro.server.rest.jackson.JacksonUtil; + +public class RestAgent { + + + public String getJson(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.get(String.class); + + } + + public String get(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.TEXT_PLAIN); + + return request.get(String.class); + + } + + public T post(String url, Object payload,Class type) { + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); + } + + +} diff --git a/micro-event-metrics/src/main/java/com/aol/micro/server/event/metrics/Configuration.java b/micro-event-metrics/src/main/java/com/oath/micro/server/event/metrics/Configuration.java similarity index 98% rename from micro-event-metrics/src/main/java/com/aol/micro/server/event/metrics/Configuration.java rename to micro-event-metrics/src/main/java/com/oath/micro/server/event/metrics/Configuration.java index 581300776..ce0fb47a3 100644 --- a/micro-event-metrics/src/main/java/com/aol/micro/server/event/metrics/Configuration.java +++ b/micro-event-metrics/src/main/java/com/oath/micro/server/event/metrics/Configuration.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.event.metrics; +package com.oath.micro.server.event.metrics; import java.util.Optional; diff --git a/micro-event-metrics/src/main/java/com/aol/micro/server/event/metrics/MetricEventsPlugin.java b/micro-event-metrics/src/main/java/com/oath/micro/server/event/metrics/MetricEventsPlugin.java similarity index 78% rename from micro-event-metrics/src/main/java/com/aol/micro/server/event/metrics/MetricEventsPlugin.java rename to micro-event-metrics/src/main/java/com/oath/micro/server/event/metrics/MetricEventsPlugin.java index 5a5b9ff18..04e9fbabc 100644 --- a/micro-event-metrics/src/main/java/com/aol/micro/server/event/metrics/MetricEventsPlugin.java +++ b/micro-event-metrics/src/main/java/com/oath/micro/server/event/metrics/MetricEventsPlugin.java @@ -1,8 +1,7 @@ -package com.aol.micro.server.event.metrics; +package com.oath.micro.server.event.metrics; -import com.aol.micro.server.Plugin; -import cyclops.collections.immutable.PersistentSetX; +import com.oath.micro.server.Plugin; import cyclops.collections.mutable.SetX; import java.util.Set; diff --git a/micro-event-metrics/src/main/java/com/aol/micro/server/event/metrics/MetricsCatcher.java b/micro-event-metrics/src/main/java/com/oath/micro/server/event/metrics/MetricsCatcher.java similarity index 91% rename from micro-event-metrics/src/main/java/com/aol/micro/server/event/metrics/MetricsCatcher.java rename to micro-event-metrics/src/main/java/com/oath/micro/server/event/metrics/MetricsCatcher.java index bcc5429ce..a0ba62dc3 100644 --- a/micro-event-metrics/src/main/java/com/aol/micro/server/event/metrics/MetricsCatcher.java +++ b/micro-event-metrics/src/main/java/com/oath/micro/server/event/metrics/MetricsCatcher.java @@ -1,22 +1,22 @@ -package com.aol.micro.server.event.metrics; +package com.oath.micro.server.event.metrics; -import com.aol.micro.server.events.GenericEvent; -import com.aol.micro.server.spring.metrics.InstantGauge; +import com.oath.micro.server.events.GenericEvent; +import com.oath.micro.server.spring.metrics.InstantGauge; import com.codahale.metrics.SlidingTimeWindowArrayReservoir; import com.codahale.metrics.Timer; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import com.aol.micro.server.errors.ErrorCode; -import com.aol.micro.server.events.JobCompleteEvent; -import com.aol.micro.server.events.JobStartEvent; -import com.aol.micro.server.events.RequestTypes.AddQuery; -import com.aol.micro.server.events.RequestTypes.RemoveQuery; -import com.aol.micro.server.events.RequestTypes.AddLabelledQuery; -import com.aol.micro.server.events.RequestTypes.RemoveLabelledQuery; -import com.aol.micro.server.events.RequestTypes.RequestData; -import com.aol.micro.server.events.SystemData; -import com.aol.micro.server.health.ErrorEvent; +import com.oath.micro.server.errors.ErrorCode; +import com.oath.micro.server.events.JobCompleteEvent; +import com.oath.micro.server.events.JobStartEvent; +import com.oath.micro.server.events.RequestTypes.AddQuery; +import com.oath.micro.server.events.RequestTypes.RemoveQuery; +import com.oath.micro.server.events.RequestTypes.AddLabelledQuery; +import com.oath.micro.server.events.RequestTypes.RemoveLabelledQuery; +import com.oath.micro.server.events.RequestTypes.RequestData; +import com.oath.micro.server.events.SystemData; +import com.oath.micro.server.health.ErrorEvent; import com.codahale.metrics.MetricRegistry; import com.google.common.eventbus.EventBus; import com.google.common.eventbus.Subscribe; diff --git a/micro-event-metrics/src/main/java/com/aol/micro/server/event/metrics/TimerManager.java b/micro-event-metrics/src/main/java/com/oath/micro/server/event/metrics/TimerManager.java similarity index 94% rename from micro-event-metrics/src/main/java/com/aol/micro/server/event/metrics/TimerManager.java rename to micro-event-metrics/src/main/java/com/oath/micro/server/event/metrics/TimerManager.java index bdc734b43..71fcaf091 100644 --- a/micro-event-metrics/src/main/java/com/aol/micro/server/event/metrics/TimerManager.java +++ b/micro-event-metrics/src/main/java/com/oath/micro/server/event/metrics/TimerManager.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.event.metrics; +package com.oath.micro.server.event.metrics; import java.util.concurrent.TimeUnit; diff --git a/micro-event-metrics/src/main/resources/META-INF/services/com.aol.micro.server.Plugin b/micro-event-metrics/src/main/resources/META-INF/services/com.aol.micro.server.Plugin deleted file mode 100644 index 8ecb40e83..000000000 --- a/micro-event-metrics/src/main/resources/META-INF/services/com.aol.micro.server.Plugin +++ /dev/null @@ -1 +0,0 @@ -com.aol.micro.server.event.metrics.MetricEventsPlugin \ No newline at end of file diff --git a/micro-event-metrics/src/main/resources/META-INF/services/com.oath.micro.server.Plugin b/micro-event-metrics/src/main/resources/META-INF/services/com.oath.micro.server.Plugin new file mode 100644 index 000000000..9395b9100 --- /dev/null +++ b/micro-event-metrics/src/main/resources/META-INF/services/com.oath.micro.server.Plugin @@ -0,0 +1 @@ +com.oath.micro.server.event.metrics.MetricEventsPlugin \ No newline at end of file diff --git a/micro-event-metrics/src/test/java/app/event/metrics/com/aol/micro/server/EventRunnerTest.java b/micro-event-metrics/src/test/java/app/event/metrics/com/aol/micro/server/EventRunnerTest.java deleted file mode 100644 index 725080083..000000000 --- a/micro-event-metrics/src/test/java/app/event/metrics/com/aol/micro/server/EventRunnerTest.java +++ /dev/null @@ -1,63 +0,0 @@ -package app.event.metrics.com.aol.micro.server; - -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - -import java.util.Map; -import java.util.concurrent.ExecutionException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.rest.jackson.JacksonUtil; -import com.aol.micro.server.testing.RestAgent; - -@Microserver -public class EventRunnerTest { - - RestAgent rest = new RestAgent(); - MicroserverApp server; - - @Before - public void startServer() { - - server = new MicroserverApp( - () -> "event-app"); - server.start(); - - } - - @After - public void stopServer() { - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException { - - assertThat(rest.get("http://localhost:8080/event-app/status/ping"), is("ok")); - - assertThat(rest.getJson("http://localhost:8080/event-app/active/jobs"), containsString("startedAt")); - assertThat(rest.getJson("http://localhost:8080/event-app/active/requests"), containsString("startedAt")); - assertThat(rest.getJson("http://localhost:8080/event-app/manifest"), containsString("Manifest")); - - String json = rest.getJson("http://localhost:8080/event-app/status/counters"); - Map map = JacksonUtil.convertFromJson(json, Map.class); - - assertThat(json, map.get("com.aol.micro.server.event.metrics.MetricsCatcher.jobs-completed-count"), - greaterThan(1)); - - String json2 = rest.getJson("http://localhost:8080/event-app/status/meters"); - Map map2 = JacksonUtil.convertFromJson(json2, Map.class); - - assertThat(json2, map2.get("com.aol.micro.server.event.metrics.MetricsCatcher.request-start-default-meter"), - greaterThan(0)); - - } - -} diff --git a/micro-event-metrics/src/test/java/app/event/metrics/com/aol/micro/server/EventStatusResource.java b/micro-event-metrics/src/test/java/app/event/metrics/com/aol/micro/server/EventStatusResource.java deleted file mode 100644 index 32e282650..000000000 --- a/micro-event-metrics/src/test/java/app/event/metrics/com/aol/micro/server/EventStatusResource.java +++ /dev/null @@ -1,59 +0,0 @@ -package app.event.metrics.com.aol.micro.server; - -import java.util.Map; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import cyclops.collections.mutable.MapX; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.RestResource; -import com.aol.micro.server.events.RequestEvents; -import com.codahale.metrics.MetricRegistry; -import com.google.common.eventbus.EventBus; - -@Component -@Path("/status") -public class EventStatusResource implements RestResource { - - private final EventBus bus; - private final MetricRegistry metrics; - - @Autowired - public EventStatusResource(EventBus bus, MetricRegistry metrics) { - this.bus = bus; - this.metrics = metrics; - } - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - bus.post(RequestEvents.start("get", 1l)); - try { - return "ok"; - } finally { - bus.post(RequestEvents.finish("get", 1l)); - } - } - - @GET - @Produces("application/json") - @Path("/counters") - public Map counters() { - return (MapX) MapX.fromMap(metrics.getCounters()) - .bimap(k -> k, v -> v.getCount()); - } - - @GET - @Produces("application/json") - @Path("/meters") - public Map meters() { - return (MapX) MapX.fromMap(metrics.getMeters()) - .bimap(k -> k, v -> v.getCount()); - } - -} \ No newline at end of file diff --git a/micro-event-metrics/src/test/java/app/event/metrics/com/aol/micro/server/EventsJob.java b/micro-event-metrics/src/test/java/app/event/metrics/com/aol/micro/server/EventsJob.java deleted file mode 100644 index 3f91e3bdf..000000000 --- a/micro-event-metrics/src/test/java/app/event/metrics/com/aol/micro/server/EventsJob.java +++ /dev/null @@ -1,19 +0,0 @@ -package app.event.metrics.com.aol.micro.server; - -import org.springframework.stereotype.Component; - -import com.aol.micro.server.events.ScheduledJob; -import com.aol.micro.server.events.SystemData; - -@Component -public class EventsJob implements ScheduledJob { - - @Override - public SystemData scheduleAndLog() { - return SystemData. builder() - .errors(0) - .processed(2) - .build(); - } - -} diff --git a/micro-event-metrics/src/test/java/app/event/metrics/com/oath/micro/server/EventRunnerTest.java b/micro-event-metrics/src/test/java/app/event/metrics/com/oath/micro/server/EventRunnerTest.java new file mode 100644 index 000000000..8cc157c42 --- /dev/null +++ b/micro-event-metrics/src/test/java/app/event/metrics/com/oath/micro/server/EventRunnerTest.java @@ -0,0 +1,63 @@ +package app.event.metrics.com.oath.micro.server; + +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + +import java.util.Map; +import java.util.concurrent.ExecutionException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.rest.jackson.JacksonUtil; +import com.oath.micro.server.testing.RestAgent; + +@Microserver +public class EventRunnerTest { + + RestAgent rest = new RestAgent(); + MicroserverApp server; + + @Before + public void startServer() { + + server = new MicroserverApp( + () -> "event-app"); + server.start(); + + } + + @After + public void stopServer() { + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException { + + assertThat(rest.get("http://localhost:8080/event-app/status/ping"), is("ok")); + + assertThat(rest.getJson("http://localhost:8080/event-app/active/jobs"), containsString("startedAt")); + assertThat(rest.getJson("http://localhost:8080/event-app/active/requests"), containsString("startedAt")); + assertThat(rest.getJson("http://localhost:8080/event-app/manifest"), containsString("Manifest")); + + String json = rest.getJson("http://localhost:8080/event-app/status/counters"); + Map map = JacksonUtil.convertFromJson(json, Map.class); + + assertThat(json, map.get("com.oath.micro.server.event.metrics.MetricsCatcher.jobs-completed-count"), + greaterThan(1)); + + String json2 = rest.getJson("http://localhost:8080/event-app/status/meters"); + Map map2 = JacksonUtil.convertFromJson(json2, Map.class); + + assertThat(json2, map2.get("com.oath.micro.server.event.metrics.MetricsCatcher.request-start-default-meter"), + greaterThan(0)); + + } + +} diff --git a/micro-event-metrics/src/test/java/app/event/metrics/com/oath/micro/server/EventStatusResource.java b/micro-event-metrics/src/test/java/app/event/metrics/com/oath/micro/server/EventStatusResource.java new file mode 100644 index 000000000..f192fd70f --- /dev/null +++ b/micro-event-metrics/src/test/java/app/event/metrics/com/oath/micro/server/EventStatusResource.java @@ -0,0 +1,59 @@ +package app.event.metrics.com.oath.micro.server; + +import java.util.Map; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import cyclops.collections.mutable.MapX; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.RestResource; +import com.oath.micro.server.events.RequestEvents; +import com.codahale.metrics.MetricRegistry; +import com.google.common.eventbus.EventBus; + +@Component +@Path("/status") +public class EventStatusResource implements RestResource { + + private final EventBus bus; + private final MetricRegistry metrics; + + @Autowired + public EventStatusResource(EventBus bus, MetricRegistry metrics) { + this.bus = bus; + this.metrics = metrics; + } + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + bus.post(RequestEvents.start("get", 1l)); + try { + return "ok"; + } finally { + bus.post(RequestEvents.finish("get", 1l)); + } + } + + @GET + @Produces("application/json") + @Path("/counters") + public Map counters() { + return (MapX) MapX.fromMap(metrics.getCounters()) + .bimap(k -> k, v -> v.getCount()); + } + + @GET + @Produces("application/json") + @Path("/meters") + public Map meters() { + return (MapX) MapX.fromMap(metrics.getMeters()) + .bimap(k -> k, v -> v.getCount()); + } + +} \ No newline at end of file diff --git a/micro-event-metrics/src/test/java/app/event/metrics/com/oath/micro/server/EventsJob.java b/micro-event-metrics/src/test/java/app/event/metrics/com/oath/micro/server/EventsJob.java new file mode 100644 index 000000000..5394bc0ce --- /dev/null +++ b/micro-event-metrics/src/test/java/app/event/metrics/com/oath/micro/server/EventsJob.java @@ -0,0 +1,19 @@ +package app.event.metrics.com.oath.micro.server; + +import org.springframework.stereotype.Component; + +import com.oath.micro.server.events.ScheduledJob; +import com.oath.micro.server.events.SystemData; + +@Component +public class EventsJob implements ScheduledJob { + + @Override + public SystemData scheduleAndLog() { + return SystemData. builder() + .errors(0) + .processed(2) + .build(); + } + +} diff --git a/micro-event-metrics/src/test/java/app/event/metrics/com/aol/micro/server/EventsSchedular.java b/micro-event-metrics/src/test/java/app/event/metrics/com/oath/micro/server/EventsSchedular.java similarity index 90% rename from micro-event-metrics/src/test/java/app/event/metrics/com/aol/micro/server/EventsSchedular.java rename to micro-event-metrics/src/test/java/app/event/metrics/com/oath/micro/server/EventsSchedular.java index 6e672c690..a1a03312b 100644 --- a/micro-event-metrics/src/test/java/app/event/metrics/com/aol/micro/server/EventsSchedular.java +++ b/micro-event-metrics/src/test/java/app/event/metrics/com/oath/micro/server/EventsSchedular.java @@ -1,4 +1,4 @@ -package app.event.metrics.com.aol.micro.server; +package app.event.metrics.com.oath.micro.server; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; diff --git a/micro-event-metrics/src/test/java/com/aol/micro/server/testing/RestAgent.java b/micro-event-metrics/src/test/java/com/aol/micro/server/testing/RestAgent.java deleted file mode 100644 index ce204f810..000000000 --- a/micro-event-metrics/src/test/java/com/aol/micro/server/testing/RestAgent.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.aol.micro.server.testing; - -import java.util.List; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.Invocation.Builder; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; - -import com.aol.micro.server.rest.jackson.JacksonUtil; - -public class RestAgent { - - - public String getJson(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.get(String.class); - - } - - public String get(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.TEXT_PLAIN); - - return request.get(String.class); - - } - - public T post(String url, Object payload,Class type) { - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); - } - - -} diff --git a/micro-event-metrics/src/test/java/com/aol/micro/server/event/metrics/MetricsCatcherConfigOffTest.java b/micro-event-metrics/src/test/java/com/oath/micro/server/event/metrics/MetricsCatcherConfigOffTest.java similarity index 93% rename from micro-event-metrics/src/test/java/com/aol/micro/server/event/metrics/MetricsCatcherConfigOffTest.java rename to micro-event-metrics/src/test/java/com/oath/micro/server/event/metrics/MetricsCatcherConfigOffTest.java index c5d0832c1..de0f9bf9a 100644 --- a/micro-event-metrics/src/test/java/com/aol/micro/server/event/metrics/MetricsCatcherConfigOffTest.java +++ b/micro-event-metrics/src/test/java/com/oath/micro/server/event/metrics/MetricsCatcherConfigOffTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.event.metrics; +package com.oath.micro.server.event.metrics; import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertThat; @@ -6,12 +6,12 @@ import org.junit.Before; import org.junit.Test; -import com.aol.micro.server.errors.ErrorCode; -import com.aol.micro.server.events.JobCompleteEvent; -import com.aol.micro.server.events.JobStartEvent; -import com.aol.micro.server.events.RequestTypes.AddQuery; -import com.aol.micro.server.events.RequestTypes.RemoveQuery; -import com.aol.micro.server.events.RequestTypes.RequestData; +import com.oath.micro.server.errors.ErrorCode; +import com.oath.micro.server.events.JobCompleteEvent; +import com.oath.micro.server.events.JobStartEvent; +import com.oath.micro.server.events.RequestTypes.AddQuery; +import com.oath.micro.server.events.RequestTypes.RemoveQuery; +import com.oath.micro.server.events.RequestTypes.RequestData; import com.codahale.metrics.MetricRegistry; import com.google.common.eventbus.EventBus; diff --git a/micro-event-metrics/src/test/java/com/aol/micro/server/event/metrics/MetricsCatcherTest.java b/micro-event-metrics/src/test/java/com/oath/micro/server/event/metrics/MetricsCatcherTest.java similarity index 94% rename from micro-event-metrics/src/test/java/com/aol/micro/server/event/metrics/MetricsCatcherTest.java rename to micro-event-metrics/src/test/java/com/oath/micro/server/event/metrics/MetricsCatcherTest.java index dc8ce6d19..057b74411 100644 --- a/micro-event-metrics/src/test/java/com/aol/micro/server/event/metrics/MetricsCatcherTest.java +++ b/micro-event-metrics/src/test/java/com/oath/micro/server/event/metrics/MetricsCatcherTest.java @@ -1,19 +1,19 @@ -package com.aol.micro.server.event.metrics; +package com.oath.micro.server.event.metrics; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThan; import static org.junit.Assert.assertThat; -import com.aol.micro.server.events.GenericEvent; +import com.oath.micro.server.events.GenericEvent; import org.junit.Before; import org.junit.Test; -import com.aol.micro.server.errors.ErrorCode; -import com.aol.micro.server.events.JobCompleteEvent; -import com.aol.micro.server.events.JobStartEvent; -import com.aol.micro.server.events.RequestTypes.AddQuery; -import com.aol.micro.server.events.RequestTypes.RemoveQuery; -import com.aol.micro.server.events.RequestTypes.RequestData; +import com.oath.micro.server.errors.ErrorCode; +import com.oath.micro.server.events.JobCompleteEvent; +import com.oath.micro.server.events.JobStartEvent; +import com.oath.micro.server.events.RequestTypes.AddQuery; +import com.oath.micro.server.events.RequestTypes.RemoveQuery; +import com.oath.micro.server.events.RequestTypes.RequestData; import com.codahale.metrics.MetricRegistry; import com.google.common.eventbus.EventBus; diff --git a/micro-event-metrics/src/test/java/com/aol/micro/server/event/metrics/TimerManagerTest.java b/micro-event-metrics/src/test/java/com/oath/micro/server/event/metrics/TimerManagerTest.java similarity index 94% rename from micro-event-metrics/src/test/java/com/aol/micro/server/event/metrics/TimerManagerTest.java rename to micro-event-metrics/src/test/java/com/oath/micro/server/event/metrics/TimerManagerTest.java index 560f0e213..3e677412c 100644 --- a/micro-event-metrics/src/test/java/com/aol/micro/server/event/metrics/TimerManagerTest.java +++ b/micro-event-metrics/src/test/java/com/oath/micro/server/event/metrics/TimerManagerTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.event.metrics; +package com.oath.micro.server.event.metrics; import org.junit.Before; import org.junit.Test; diff --git a/micro-event-metrics/src/test/java/com/oath/micro/server/testing/RestAgent.java b/micro-event-metrics/src/test/java/com/oath/micro/server/testing/RestAgent.java new file mode 100644 index 000000000..b2b86303e --- /dev/null +++ b/micro-event-metrics/src/test/java/com/oath/micro/server/testing/RestAgent.java @@ -0,0 +1,53 @@ +package com.oath.micro.server.testing; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.Invocation.Builder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; + +import com.oath.micro.server.rest.jackson.JacksonUtil; + +public class RestAgent { + + + public String getJson(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.get(String.class); + + } + + public String get(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.TEXT_PLAIN); + + return request.get(String.class); + + } + + public T post(String url, Object payload,Class type) { + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); + } + + +} diff --git a/micro-events/src/main/java/com/aol/micro/server/events/SchedulableJob.java b/micro-events/src/main/java/com/aol/micro/server/events/SchedulableJob.java deleted file mode 100644 index 9fa13d1bd..000000000 --- a/micro-events/src/main/java/com/aol/micro/server/events/SchedulableJob.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.aol.micro.server.events; - -public interface SchedulableJob extends ScheduledJob { - boolean isScheduled(); -} diff --git a/micro-events/src/main/java/com/aol/micro/server/events/ScheduledJob.java b/micro-events/src/main/java/com/aol/micro/server/events/ScheduledJob.java deleted file mode 100644 index 3c96f7e59..000000000 --- a/micro-events/src/main/java/com/aol/micro/server/events/ScheduledJob.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.aol.micro.server.events; - - - -public interface ScheduledJob { - SystemData scheduleAndLog(); -} diff --git a/micro-events/src/main/java/com/aol/micro/server/events/StartedAt.java b/micro-events/src/main/java/com/aol/micro/server/events/StartedAt.java deleted file mode 100644 index 5ee00c046..000000000 --- a/micro-events/src/main/java/com/aol/micro/server/events/StartedAt.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.aol.micro.server.events; - -public interface StartedAt { - - public long getStartedAt(); -} diff --git a/micro-events/src/main/java/com/aol/micro/server/events/plugin/EventsPlugin.java b/micro-events/src/main/java/com/aol/micro/server/events/plugin/EventsPlugin.java deleted file mode 100644 index 41894b860..000000000 --- a/micro-events/src/main/java/com/aol/micro/server/events/plugin/EventsPlugin.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.aol.micro.server.events.plugin; - - -import com.aol.micro.server.Plugin; -import com.aol.micro.server.events.ConfigureActiveJobsAspect; -import com.aol.micro.server.rest.resources.ConfigureResources; -import cyclops.collections.immutable.PersistentSetX; -import cyclops.collections.mutable.SetX; - -import java.util.Set; - - -/** - * - * Collections of Spring configuration classes (Classes annotated with @Configuration) - * that configure various useful pieces of functionality - such as property file loading, - * datasources, scheduling etc - * - * @author johnmcclean - * - */ -public class EventsPlugin implements Plugin{ - - @Override - public Set springClasses() { - return SetX.of( - ConfigureActiveJobsAspect.class, - ConfigureResources.class); - } - - - -} diff --git a/micro-events/src/main/java/com/aol/micro/server/events/ActiveEvents.java b/micro-events/src/main/java/com/oath/micro/server/events/ActiveEvents.java similarity index 96% rename from micro-events/src/main/java/com/aol/micro/server/events/ActiveEvents.java rename to micro-events/src/main/java/com/oath/micro/server/events/ActiveEvents.java index 8819cee36..86b0adfc4 100644 --- a/micro-events/src/main/java/com/aol/micro/server/events/ActiveEvents.java +++ b/micro-events/src/main/java/com/oath/micro/server/events/ActiveEvents.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.events; +package com.oath.micro.server.events; import java.text.DateFormat; import java.text.SimpleDateFormat; @@ -9,7 +9,7 @@ import java.util.concurrent.ConcurrentLinkedDeque; import java.util.concurrent.atomic.AtomicInteger; -import com.aol.micro.server.rest.jackson.JacksonUtil; +import com.oath.micro.server.rest.jackson.JacksonUtil; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; diff --git a/micro-events/src/main/java/com/aol/micro/server/events/AddEvent.java b/micro-events/src/main/java/com/oath/micro/server/events/AddEvent.java similarity index 79% rename from micro-events/src/main/java/com/aol/micro/server/events/AddEvent.java rename to micro-events/src/main/java/com/oath/micro/server/events/AddEvent.java index 5405351ec..b4d6f8bf6 100644 --- a/micro-events/src/main/java/com/aol/micro/server/events/AddEvent.java +++ b/micro-events/src/main/java/com/oath/micro/server/events/AddEvent.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.events; +package com.oath.micro.server.events; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/micro-events/src/main/java/com/aol/micro/server/events/BaseEventInfo.java b/micro-events/src/main/java/com/oath/micro/server/events/BaseEventInfo.java similarity index 93% rename from micro-events/src/main/java/com/aol/micro/server/events/BaseEventInfo.java rename to micro-events/src/main/java/com/oath/micro/server/events/BaseEventInfo.java index 6d8a5a329..065e140df 100644 --- a/micro-events/src/main/java/com/aol/micro/server/events/BaseEventInfo.java +++ b/micro-events/src/main/java/com/oath/micro/server/events/BaseEventInfo.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.events; +package com.oath.micro.server.events; import java.text.DateFormat; import java.text.SimpleDateFormat; diff --git a/micro-events/src/main/java/com/aol/micro/server/events/ConfigureActiveJobsAspect.java b/micro-events/src/main/java/com/oath/micro/server/events/ConfigureActiveJobsAspect.java similarity index 97% rename from micro-events/src/main/java/com/aol/micro/server/events/ConfigureActiveJobsAspect.java rename to micro-events/src/main/java/com/oath/micro/server/events/ConfigureActiveJobsAspect.java index e0776ef13..e5b87e019 100644 --- a/micro-events/src/main/java/com/aol/micro/server/events/ConfigureActiveJobsAspect.java +++ b/micro-events/src/main/java/com/oath/micro/server/events/ConfigureActiveJobsAspect.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.events; +package com.oath.micro.server.events; import javax.annotation.Resource; diff --git a/micro-events/src/main/java/com/aol/micro/server/events/GenericEvent.java b/micro-events/src/main/java/com/oath/micro/server/events/GenericEvent.java similarity index 97% rename from micro-events/src/main/java/com/aol/micro/server/events/GenericEvent.java rename to micro-events/src/main/java/com/oath/micro/server/events/GenericEvent.java index b8d52d19e..bf3fbc893 100644 --- a/micro-events/src/main/java/com/aol/micro/server/events/GenericEvent.java +++ b/micro-events/src/main/java/com/oath/micro/server/events/GenericEvent.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.events; +package com.oath.micro.server.events; import com.google.common.eventbus.EventBus; import lombok.AllArgsConstructor; diff --git a/micro-events/src/main/java/com/aol/micro/server/events/JobCompleteEvent.java b/micro-events/src/main/java/com/oath/micro/server/events/JobCompleteEvent.java similarity index 89% rename from micro-events/src/main/java/com/aol/micro/server/events/JobCompleteEvent.java rename to micro-events/src/main/java/com/oath/micro/server/events/JobCompleteEvent.java index 6edf85fa3..7e71b80af 100644 --- a/micro-events/src/main/java/com/aol/micro/server/events/JobCompleteEvent.java +++ b/micro-events/src/main/java/com/oath/micro/server/events/JobCompleteEvent.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.events; +package com.oath.micro.server.events; import java.util.Date; diff --git a/micro-events/src/main/java/com/aol/micro/server/events/JobName.java b/micro-events/src/main/java/com/oath/micro/server/events/JobName.java similarity index 97% rename from micro-events/src/main/java/com/aol/micro/server/events/JobName.java rename to micro-events/src/main/java/com/oath/micro/server/events/JobName.java index a20475eea..26b244372 100644 --- a/micro-events/src/main/java/com/aol/micro/server/events/JobName.java +++ b/micro-events/src/main/java/com/oath/micro/server/events/JobName.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.events; +package com.oath.micro.server.events; import java.util.stream.Stream; diff --git a/micro-events/src/main/java/com/aol/micro/server/events/JobStartEvent.java b/micro-events/src/main/java/com/oath/micro/server/events/JobStartEvent.java similarity index 86% rename from micro-events/src/main/java/com/aol/micro/server/events/JobStartEvent.java rename to micro-events/src/main/java/com/oath/micro/server/events/JobStartEvent.java index ae78ab7b2..0c3329545 100644 --- a/micro-events/src/main/java/com/aol/micro/server/events/JobStartEvent.java +++ b/micro-events/src/main/java/com/oath/micro/server/events/JobStartEvent.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.events; +package com.oath.micro.server.events; import java.util.Date; diff --git a/micro-events/src/main/java/com/aol/micro/server/events/JobsBeingExecuted.java b/micro-events/src/main/java/com/oath/micro/server/events/JobsBeingExecuted.java similarity index 97% rename from micro-events/src/main/java/com/aol/micro/server/events/JobsBeingExecuted.java rename to micro-events/src/main/java/com/oath/micro/server/events/JobsBeingExecuted.java index 81f3537b4..344a4fa64 100644 --- a/micro-events/src/main/java/com/aol/micro/server/events/JobsBeingExecuted.java +++ b/micro-events/src/main/java/com/oath/micro/server/events/JobsBeingExecuted.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.events; +package com.oath.micro.server.events; import java.util.Optional; import java.util.Random; @@ -47,7 +47,7 @@ public JobsBeingExecuted(EventBus bus) { bus, 10, JobName.Types.SIMPLE); } - @Around("execution(* com.aol.micro.server.events.ScheduledJob.scheduleAndLog(..))") + @Around("execution(* com.oath.micro.server.events.ScheduledJob.scheduleAndLog(..))") public Object aroundScheduledJob(ProceedingJoinPoint pjp) throws Throwable { String type = jobNameType.getCreator() diff --git a/micro-events/src/main/java/com/aol/micro/server/events/LabelledEvents.java b/micro-events/src/main/java/com/oath/micro/server/events/LabelledEvents.java similarity index 94% rename from micro-events/src/main/java/com/aol/micro/server/events/LabelledEvents.java rename to micro-events/src/main/java/com/oath/micro/server/events/LabelledEvents.java index e77d6f512..b1e549a51 100644 --- a/micro-events/src/main/java/com/aol/micro/server/events/LabelledEvents.java +++ b/micro-events/src/main/java/com/oath/micro/server/events/LabelledEvents.java @@ -1,8 +1,8 @@ -package com.aol.micro.server.events; +package com.oath.micro.server.events; -import com.aol.micro.server.events.RequestTypes.AddLabelledQuery; -import com.aol.micro.server.events.RequestTypes.RemoveLabelledQuery; -import com.aol.micro.server.events.RequestTypes.RequestData; +import com.oath.micro.server.events.RequestTypes.AddLabelledQuery; +import com.oath.micro.server.events.RequestTypes.RemoveLabelledQuery; +import com.oath.micro.server.events.RequestTypes.RequestData; import com.google.common.eventbus.EventBus; diff --git a/micro-events/src/main/java/com/aol/micro/server/events/LoggingRateLimiter.java b/micro-events/src/main/java/com/oath/micro/server/events/LoggingRateLimiter.java similarity index 96% rename from micro-events/src/main/java/com/aol/micro/server/events/LoggingRateLimiter.java rename to micro-events/src/main/java/com/oath/micro/server/events/LoggingRateLimiter.java index 06ae06770..622c22883 100644 --- a/micro-events/src/main/java/com/aol/micro/server/events/LoggingRateLimiter.java +++ b/micro-events/src/main/java/com/oath/micro/server/events/LoggingRateLimiter.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.events; +package com.oath.micro.server.events; import java.util.Date; diff --git a/micro-events/src/main/java/com/aol/micro/server/events/RemoveEvent.java b/micro-events/src/main/java/com/oath/micro/server/events/RemoveEvent.java similarity index 79% rename from micro-events/src/main/java/com/aol/micro/server/events/RemoveEvent.java rename to micro-events/src/main/java/com/oath/micro/server/events/RemoveEvent.java index 966219f84..da74e3ad0 100644 --- a/micro-events/src/main/java/com/aol/micro/server/events/RemoveEvent.java +++ b/micro-events/src/main/java/com/oath/micro/server/events/RemoveEvent.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.events; +package com.oath.micro.server.events; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/micro-events/src/main/java/com/aol/micro/server/events/RequestEvents.java b/micro-events/src/main/java/com/oath/micro/server/events/RequestEvents.java similarity index 95% rename from micro-events/src/main/java/com/aol/micro/server/events/RequestEvents.java rename to micro-events/src/main/java/com/oath/micro/server/events/RequestEvents.java index 576811ad4..42b10f58f 100644 --- a/micro-events/src/main/java/com/aol/micro/server/events/RequestEvents.java +++ b/micro-events/src/main/java/com/oath/micro/server/events/RequestEvents.java @@ -1,8 +1,8 @@ -package com.aol.micro.server.events; +package com.oath.micro.server.events; -import com.aol.micro.server.events.RequestTypes.AddQuery; -import com.aol.micro.server.events.RequestTypes.RemoveQuery; -import com.aol.micro.server.events.RequestTypes.RequestData; +import com.oath.micro.server.events.RequestTypes.AddQuery; +import com.oath.micro.server.events.RequestTypes.RemoveQuery; +import com.oath.micro.server.events.RequestTypes.RequestData; import com.google.common.eventbus.EventBus; /** diff --git a/micro-events/src/main/java/com/aol/micro/server/events/RequestTypes.java b/micro-events/src/main/java/com/oath/micro/server/events/RequestTypes.java similarity index 96% rename from micro-events/src/main/java/com/aol/micro/server/events/RequestTypes.java rename to micro-events/src/main/java/com/oath/micro/server/events/RequestTypes.java index bc1f22086..ff14f91ee 100644 --- a/micro-events/src/main/java/com/aol/micro/server/events/RequestTypes.java +++ b/micro-events/src/main/java/com/oath/micro/server/events/RequestTypes.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.events; +package com.oath.micro.server.events; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -6,7 +6,7 @@ import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; -import com.aol.micro.server.rest.jackson.JacksonUtil; +import com.oath.micro.server.rest.jackson.JacksonUtil; import com.google.common.eventbus.EventBus; import com.google.common.eventbus.Subscribe; diff --git a/micro-events/src/main/java/com/aol/micro/server/events/RequestsBeingExecuted.java b/micro-events/src/main/java/com/oath/micro/server/events/RequestsBeingExecuted.java similarity index 90% rename from micro-events/src/main/java/com/aol/micro/server/events/RequestsBeingExecuted.java rename to micro-events/src/main/java/com/oath/micro/server/events/RequestsBeingExecuted.java index 3d12c5991..55cf76a9e 100644 --- a/micro-events/src/main/java/com/aol/micro/server/events/RequestsBeingExecuted.java +++ b/micro-events/src/main/java/com/oath/micro/server/events/RequestsBeingExecuted.java @@ -1,10 +1,10 @@ -package com.aol.micro.server.events; +package com.oath.micro.server.events; import java.util.Map; import org.springframework.beans.factory.annotation.Qualifier; -import com.aol.micro.server.events.RequestTypes.RequestData; +import com.oath.micro.server.events.RequestTypes.RequestData; import com.google.common.eventbus.EventBus; import lombok.Getter; diff --git a/micro-events/src/main/java/com/oath/micro/server/events/SchedulableJob.java b/micro-events/src/main/java/com/oath/micro/server/events/SchedulableJob.java new file mode 100644 index 000000000..19712af3d --- /dev/null +++ b/micro-events/src/main/java/com/oath/micro/server/events/SchedulableJob.java @@ -0,0 +1,5 @@ +package com.oath.micro.server.events; + +public interface SchedulableJob extends ScheduledJob { + boolean isScheduled(); +} diff --git a/micro-events/src/main/java/com/oath/micro/server/events/ScheduledJob.java b/micro-events/src/main/java/com/oath/micro/server/events/ScheduledJob.java new file mode 100644 index 000000000..f6e308116 --- /dev/null +++ b/micro-events/src/main/java/com/oath/micro/server/events/ScheduledJob.java @@ -0,0 +1,7 @@ +package com.oath.micro.server.events; + + + +public interface ScheduledJob { + SystemData scheduleAndLog(); +} diff --git a/micro-events/src/main/java/com/oath/micro/server/events/StartedAt.java b/micro-events/src/main/java/com/oath/micro/server/events/StartedAt.java new file mode 100644 index 000000000..97618c833 --- /dev/null +++ b/micro-events/src/main/java/com/oath/micro/server/events/StartedAt.java @@ -0,0 +1,6 @@ +package com.oath.micro.server.events; + +public interface StartedAt { + + public long getStartedAt(); +} diff --git a/micro-events/src/main/java/com/aol/micro/server/events/SystemData.java b/micro-events/src/main/java/com/oath/micro/server/events/SystemData.java similarity index 95% rename from micro-events/src/main/java/com/aol/micro/server/events/SystemData.java rename to micro-events/src/main/java/com/oath/micro/server/events/SystemData.java index 60d7f2648..d19f6b972 100644 --- a/micro-events/src/main/java/com/aol/micro/server/events/SystemData.java +++ b/micro-events/src/main/java/com/oath/micro/server/events/SystemData.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.events; +package com.oath.micro.server.events; import java.util.Map; import java.util.Random; diff --git a/micro-events/src/main/java/com/oath/micro/server/events/plugin/EventsPlugin.java b/micro-events/src/main/java/com/oath/micro/server/events/plugin/EventsPlugin.java new file mode 100644 index 000000000..fa1d125aa --- /dev/null +++ b/micro-events/src/main/java/com/oath/micro/server/events/plugin/EventsPlugin.java @@ -0,0 +1,32 @@ +package com.oath.micro.server.events.plugin; + + +import com.oath.micro.server.Plugin; +import com.oath.micro.server.events.ConfigureActiveJobsAspect; +import com.oath.micro.server.rest.resources.ConfigureResources; +import cyclops.collections.mutable.SetX; + +import java.util.Set; + + +/** + * + * Collections of Spring configuration classes (Classes annotated with @Configuration) + * that configure various useful pieces of functionality - such as property file loading, + * datasources, scheduling etc + * + * @author johnmcclean + * + */ +public class EventsPlugin implements Plugin{ + + @Override + public Set springClasses() { + return SetX.of( + ConfigureActiveJobsAspect.class, + ConfigureResources.class); + } + + + +} diff --git a/micro-events/src/main/java/com/aol/micro/server/rest/resources/ActiveResource.java b/micro-events/src/main/java/com/oath/micro/server/rest/resources/ActiveResource.java similarity index 86% rename from micro-events/src/main/java/com/aol/micro/server/rest/resources/ActiveResource.java rename to micro-events/src/main/java/com/oath/micro/server/rest/resources/ActiveResource.java index 7be250476..516163334 100644 --- a/micro-events/src/main/java/com/aol/micro/server/rest/resources/ActiveResource.java +++ b/micro-events/src/main/java/com/oath/micro/server/rest/resources/ActiveResource.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.rest.resources; +package com.oath.micro.server.rest.resources; import javax.ws.rs.GET; import javax.ws.rs.Path; @@ -11,11 +11,11 @@ import org.springframework.beans.factory.annotation.Autowired; -import com.aol.micro.server.WorkerThreads; -import com.aol.micro.server.auto.discovery.CommonRestResource; -import com.aol.micro.server.auto.discovery.SingletonRestResource; -import com.aol.micro.server.events.JobsBeingExecuted; -import com.aol.micro.server.events.RequestTypes; +import com.oath.micro.server.WorkerThreads; +import com.oath.micro.server.auto.discovery.CommonRestResource; +import com.oath.micro.server.auto.discovery.SingletonRestResource; +import com.oath.micro.server.events.JobsBeingExecuted; +import com.oath.micro.server.events.RequestTypes; @Path("/active") public class ActiveResource implements CommonRestResource, SingletonRestResource { diff --git a/micro-events/src/main/java/com/aol/micro/server/rest/resources/ConfigureResources.java b/micro-events/src/main/java/com/oath/micro/server/rest/resources/ConfigureResources.java similarity index 82% rename from micro-events/src/main/java/com/aol/micro/server/rest/resources/ConfigureResources.java rename to micro-events/src/main/java/com/oath/micro/server/rest/resources/ConfigureResources.java index 4d59a9af1..c1b9211d9 100644 --- a/micro-events/src/main/java/com/aol/micro/server/rest/resources/ConfigureResources.java +++ b/micro-events/src/main/java/com/oath/micro/server/rest/resources/ConfigureResources.java @@ -1,12 +1,12 @@ -package com.aol.micro.server.rest.resources; +package com.oath.micro.server.rest.resources; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import com.aol.micro.server.events.JobsBeingExecuted; -import com.aol.micro.server.events.RequestTypes; +import com.oath.micro.server.events.JobsBeingExecuted; +import com.oath.micro.server.events.RequestTypes; @Configuration public class ConfigureResources { diff --git a/micro-events/src/main/java/com/aol/micro/server/rest/resources/ManifestResource.java b/micro-events/src/main/java/com/oath/micro/server/rest/resources/ManifestResource.java similarity index 88% rename from micro-events/src/main/java/com/aol/micro/server/rest/resources/ManifestResource.java rename to micro-events/src/main/java/com/oath/micro/server/rest/resources/ManifestResource.java index 309d45c91..2011e4cf3 100644 --- a/micro-events/src/main/java/com/aol/micro/server/rest/resources/ManifestResource.java +++ b/micro-events/src/main/java/com/oath/micro/server/rest/resources/ManifestResource.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.rest.resources; +package com.oath.micro.server.rest.resources; import java.io.InputStream; import java.util.HashMap; @@ -20,9 +20,9 @@ import org.springframework.stereotype.Component; -import com.aol.micro.server.WorkerThreads; -import com.aol.micro.server.auto.discovery.CommonRestResource; -import com.aol.micro.server.auto.discovery.SingletonRestResource; +import com.oath.micro.server.WorkerThreads; +import com.oath.micro.server.auto.discovery.CommonRestResource; +import com.oath.micro.server.auto.discovery.SingletonRestResource; @Path("/manifest") @Component diff --git a/micro-events/src/main/resources/META-INF/services/com.aol.micro.server.Plugin b/micro-events/src/main/resources/META-INF/services/com.aol.micro.server.Plugin deleted file mode 100644 index 8857f9e9a..000000000 --- a/micro-events/src/main/resources/META-INF/services/com.aol.micro.server.Plugin +++ /dev/null @@ -1 +0,0 @@ -com.aol.micro.server.events.plugin.EventsPlugin \ No newline at end of file diff --git a/micro-events/src/main/resources/META-INF/services/com.oath.micro.server.Plugin b/micro-events/src/main/resources/META-INF/services/com.oath.micro.server.Plugin new file mode 100644 index 000000000..1fe2ea907 --- /dev/null +++ b/micro-events/src/main/resources/META-INF/services/com.oath.micro.server.Plugin @@ -0,0 +1 @@ +com.oath.micro.server.events.plugin.EventsPlugin \ No newline at end of file diff --git a/micro-events/src/test/java/NoPackageTest.java b/micro-events/src/test/java/NoPackageTest.java index ecbba48d0..e608c44a0 100644 --- a/micro-events/src/test/java/NoPackageTest.java +++ b/micro-events/src/test/java/NoPackageTest.java @@ -3,8 +3,8 @@ import org.junit.Test; -import com.aol.micro.server.events.JobName; -import com.aol.micro.server.events.JobName.Types; +import com.oath.micro.server.events.JobName; +import com.oath.micro.server.events.JobName.Types; public class NoPackageTest { JobName one = Types.PACKAGE.getCreator(); diff --git a/micro-events/src/test/java/app/events/com/aol/micro/server/EventRunnerTest.java b/micro-events/src/test/java/app/events/com/aol/micro/server/EventRunnerTest.java deleted file mode 100644 index 14772d493..000000000 --- a/micro-events/src/test/java/app/events/com/aol/micro/server/EventRunnerTest.java +++ /dev/null @@ -1,66 +0,0 @@ -package app.events.com.aol.micro.server; - -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.testing.RestAgent; - -@Microserver -public class EventRunnerTest { - - RestAgent rest = new RestAgent(); - MicroserverApp server; - - @Before - public void startServer() { - - server = new MicroserverApp( - () -> "event-app"); - server.start(); - - } - - @After - public void stopServer() { - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException { - - assertThat(rest.get("http://localhost:8080/event-app/status/ping"), is("ok")); - - assertThat(rest.getJson("http://localhost:8080/event-app/active/jobs"), containsString("startedAt")); - assertThat(rest.getJson("http://localhost:8080/event-app/active/requests"), containsString("startedAt")); - assertThat(rest.getJson("http://localhost:8080/event-app/manifest"), containsString("Manifest")); - assertThat(rest.getJson("http://localhost:8080/event-app/manifest"), containsString("Manifest-Version")); - - System.out.println(rest.getJson("http://localhost:8080/event-app/manifest")); - - } - - @Test - public void runAppAndBasicTestCustom() throws InterruptedException, ExecutionException { - - assertThat(rest.get("http://localhost:8080/event-app/status/ping-custom"), is("ok")); - - assertThat(rest.getJson("http://localhost:8080/event-app/active/jobs?type=custom"), - containsString("startedAt")); - assertThat(rest.getJson("http://localhost:8080/event-app/active/all-requests"), containsString("startedAt")); - assertThat(rest.getJson("http://localhost:8080/event-app/manifest"), containsString("Manifest")); - assertThat(rest.getJson("http://localhost:8080/event-app/manifest"), containsString("Manifest-Version")); - - System.out.println(rest.getJson("http://localhost:8080/event-app/manifest")); - - } - -} diff --git a/micro-events/src/test/java/app/events/com/aol/micro/server/EventStatusResource.java b/micro-events/src/test/java/app/events/com/aol/micro/server/EventStatusResource.java deleted file mode 100644 index 18ffbbfe7..000000000 --- a/micro-events/src/test/java/app/events/com/aol/micro/server/EventStatusResource.java +++ /dev/null @@ -1,49 +0,0 @@ -package app.events.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.RestResource; -import com.aol.micro.server.events.RequestEvents; -import com.google.common.eventbus.EventBus; - -@Component -@Path("/status") -public class EventStatusResource implements RestResource { - - private final EventBus bus; - - @Autowired - public EventStatusResource(EventBus bus) { - this.bus = bus; - } - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - bus.post(RequestEvents.start("get", 1l)); - try { - return "ok"; - } finally { - bus.post(RequestEvents.finish("get", 1l)); - } - } - - @GET - @Produces("text/plain") - @Path("/ping-custom") - public String pingCustom() { - bus.post(RequestEvents.start("get", 1l, "custom")); - try { - return "ok"; - } finally { - bus.post(RequestEvents.finish("get", 1l, "custom")); - } - } - -} \ No newline at end of file diff --git a/micro-events/src/test/java/app/events/com/aol/micro/server/Job.java b/micro-events/src/test/java/app/events/com/aol/micro/server/Job.java deleted file mode 100644 index 39f9f6222..000000000 --- a/micro-events/src/test/java/app/events/com/aol/micro/server/Job.java +++ /dev/null @@ -1,16 +0,0 @@ -package app.events.com.aol.micro.server; - -import org.springframework.stereotype.Component; - -import com.aol.micro.server.events.ScheduledJob; -import com.aol.micro.server.events.SystemData; - -@Component -public class Job implements ScheduledJob{ - - @Override - public SystemData scheduleAndLog() { - return SystemData.builder().errors(0).processed(2).build(); - } - -} diff --git a/micro-events/src/test/java/app/events/com/aol/micro/server/Schedular.java b/micro-events/src/test/java/app/events/com/aol/micro/server/Schedular.java deleted file mode 100644 index 8b99c6930..000000000 --- a/micro-events/src/test/java/app/events/com/aol/micro/server/Schedular.java +++ /dev/null @@ -1,21 +0,0 @@ -package app.events.com.aol.micro.server; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Component; - -@Component -public class Schedular { - - private final Job job; - - @Autowired - public Schedular(final Job job){ - this.job=job; - } - - @Scheduled(fixedDelay=1) - public synchronized void scheduleTask(){ - job.scheduleAndLog(); - } -} diff --git a/micro-events/src/test/java/app/events/com/oath/micro/server/EventRunnerTest.java b/micro-events/src/test/java/app/events/com/oath/micro/server/EventRunnerTest.java new file mode 100644 index 000000000..4b69955d3 --- /dev/null +++ b/micro-events/src/test/java/app/events/com/oath/micro/server/EventRunnerTest.java @@ -0,0 +1,66 @@ +package app.events.com.oath.micro.server; + +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.testing.RestAgent; + +@Microserver +public class EventRunnerTest { + + RestAgent rest = new RestAgent(); + MicroserverApp server; + + @Before + public void startServer() { + + server = new MicroserverApp( + () -> "event-app"); + server.start(); + + } + + @After + public void stopServer() { + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException { + + assertThat(rest.get("http://localhost:8080/event-app/status/ping"), is("ok")); + + assertThat(rest.getJson("http://localhost:8080/event-app/active/jobs"), containsString("startedAt")); + assertThat(rest.getJson("http://localhost:8080/event-app/active/requests"), containsString("startedAt")); + assertThat(rest.getJson("http://localhost:8080/event-app/manifest"), containsString("Manifest")); + assertThat(rest.getJson("http://localhost:8080/event-app/manifest"), containsString("Manifest-Version")); + + System.out.println(rest.getJson("http://localhost:8080/event-app/manifest")); + + } + + @Test + public void runAppAndBasicTestCustom() throws InterruptedException, ExecutionException { + + assertThat(rest.get("http://localhost:8080/event-app/status/ping-custom"), is("ok")); + + assertThat(rest.getJson("http://localhost:8080/event-app/active/jobs?type=custom"), + containsString("startedAt")); + assertThat(rest.getJson("http://localhost:8080/event-app/active/all-requests"), containsString("startedAt")); + assertThat(rest.getJson("http://localhost:8080/event-app/manifest"), containsString("Manifest")); + assertThat(rest.getJson("http://localhost:8080/event-app/manifest"), containsString("Manifest-Version")); + + System.out.println(rest.getJson("http://localhost:8080/event-app/manifest")); + + } + +} diff --git a/micro-events/src/test/java/app/events/com/oath/micro/server/EventStatusResource.java b/micro-events/src/test/java/app/events/com/oath/micro/server/EventStatusResource.java new file mode 100644 index 000000000..bbccb6abb --- /dev/null +++ b/micro-events/src/test/java/app/events/com/oath/micro/server/EventStatusResource.java @@ -0,0 +1,49 @@ +package app.events.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.RestResource; +import com.oath.micro.server.events.RequestEvents; +import com.google.common.eventbus.EventBus; + +@Component +@Path("/status") +public class EventStatusResource implements RestResource { + + private final EventBus bus; + + @Autowired + public EventStatusResource(EventBus bus) { + this.bus = bus; + } + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + bus.post(RequestEvents.start("get", 1l)); + try { + return "ok"; + } finally { + bus.post(RequestEvents.finish("get", 1l)); + } + } + + @GET + @Produces("text/plain") + @Path("/ping-custom") + public String pingCustom() { + bus.post(RequestEvents.start("get", 1l, "custom")); + try { + return "ok"; + } finally { + bus.post(RequestEvents.finish("get", 1l, "custom")); + } + } + +} \ No newline at end of file diff --git a/micro-events/src/test/java/app/events/com/oath/micro/server/Job.java b/micro-events/src/test/java/app/events/com/oath/micro/server/Job.java new file mode 100644 index 000000000..b39b7cff8 --- /dev/null +++ b/micro-events/src/test/java/app/events/com/oath/micro/server/Job.java @@ -0,0 +1,16 @@ +package app.events.com.oath.micro.server; + +import org.springframework.stereotype.Component; + +import com.oath.micro.server.events.ScheduledJob; +import com.oath.micro.server.events.SystemData; + +@Component +public class Job implements ScheduledJob{ + + @Override + public SystemData scheduleAndLog() { + return SystemData.builder().errors(0).processed(2).build(); + } + +} diff --git a/micro-events/src/test/java/app/events/com/oath/micro/server/Schedular.java b/micro-events/src/test/java/app/events/com/oath/micro/server/Schedular.java new file mode 100644 index 000000000..c93a9c537 --- /dev/null +++ b/micro-events/src/test/java/app/events/com/oath/micro/server/Schedular.java @@ -0,0 +1,21 @@ +package app.events.com.oath.micro.server; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +@Component +public class Schedular { + + private final Job job; + + @Autowired + public Schedular(final Job job){ + this.job=job; + } + + @Scheduled(fixedDelay=1) + public synchronized void scheduleTask(){ + job.scheduleAndLog(); + } +} diff --git a/micro-events/src/test/java/app/groovy/StatusGroovy.groovy b/micro-events/src/test/java/app/groovy/StatusGroovy.groovy index c78d4f87f..f733d3c3f 100644 --- a/micro-events/src/test/java/app/groovy/StatusGroovy.groovy +++ b/micro-events/src/test/java/app/groovy/StatusGroovy.groovy @@ -4,12 +4,10 @@ import javax.ws.rs.GET import javax.ws.rs.Path import javax.ws.rs.Produces -import app.groovy.StatusGroovy; - -import com.aol.micro.server.MicroserverApp -import com.aol.micro.server.auto.discovery.Rest -import com.aol.micro.server.config.Microserver -import com.aol.micro.server.module.Module +import com.oath.micro.server.MicroserverApp +import com.oath.micro.server.auto.discovery.Rest +import com.oath.micro.server.config.Microserver +import com.oath.micro.server.module.Module @Rest @Path("/status") diff --git a/micro-events/src/test/java/app/multi/events/com/aol/micro/server/Job.java b/micro-events/src/test/java/app/multi/events/com/aol/micro/server/Job.java deleted file mode 100644 index 00ffeb3bc..000000000 --- a/micro-events/src/test/java/app/multi/events/com/aol/micro/server/Job.java +++ /dev/null @@ -1,16 +0,0 @@ -package app.multi.events.com.aol.micro.server; - -import org.springframework.stereotype.Component; - -import com.aol.micro.server.events.ScheduledJob; -import com.aol.micro.server.events.SystemData; - -@Component -public class Job implements ScheduledJob{ - - @Override - public SystemData scheduleAndLog() { - return SystemData.builder().errors(0).processed(2).build(); - } - -} diff --git a/micro-events/src/test/java/app/multi/events/com/aol/micro/server/Schedular.java b/micro-events/src/test/java/app/multi/events/com/aol/micro/server/Schedular.java deleted file mode 100644 index 2bd35a2d8..000000000 --- a/micro-events/src/test/java/app/multi/events/com/aol/micro/server/Schedular.java +++ /dev/null @@ -1,21 +0,0 @@ -package app.multi.events.com.aol.micro.server; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Component; - -@Component -public class Schedular { - - private final Job job; - - @Autowired - public Schedular(final Job job){ - this.job=job; - } - - @Scheduled(fixedDelay=1) - public synchronized void scheduleTask(){ - job.scheduleAndLog(); - } -} diff --git a/micro-events/src/test/java/app/multi/events/com/oath/micro/server/Job.java b/micro-events/src/test/java/app/multi/events/com/oath/micro/server/Job.java new file mode 100644 index 000000000..5b76af49a --- /dev/null +++ b/micro-events/src/test/java/app/multi/events/com/oath/micro/server/Job.java @@ -0,0 +1,16 @@ +package app.multi.events.com.oath.micro.server; + +import org.springframework.stereotype.Component; + +import com.oath.micro.server.events.ScheduledJob; +import com.oath.micro.server.events.SystemData; + +@Component +public class Job implements ScheduledJob{ + + @Override + public SystemData scheduleAndLog() { + return SystemData.builder().errors(0).processed(2).build(); + } + +} diff --git a/micro-events/src/test/java/app/multi/events/com/aol/micro/server/MulitEventRunnerTest.java b/micro-events/src/test/java/app/multi/events/com/oath/micro/server/MulitEventRunnerTest.java similarity index 92% rename from micro-events/src/test/java/app/multi/events/com/aol/micro/server/MulitEventRunnerTest.java rename to micro-events/src/test/java/app/multi/events/com/oath/micro/server/MulitEventRunnerTest.java index 1c22388e2..3ac4f5dc5 100644 --- a/micro-events/src/test/java/app/multi/events/com/aol/micro/server/MulitEventRunnerTest.java +++ b/micro-events/src/test/java/app/multi/events/com/oath/micro/server/MulitEventRunnerTest.java @@ -1,4 +1,4 @@ -package app.multi.events.com.aol.micro.server; +package app.multi.events.com.oath.micro.server; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.is; @@ -10,9 +10,9 @@ import org.junit.Before; import org.junit.Test; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.testing.RestAgent; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.testing.RestAgent; @Microserver public class MulitEventRunnerTest { diff --git a/micro-events/src/test/java/app/multi/events/com/aol/micro/server/MultiEventStatusResource.java b/micro-events/src/test/java/app/multi/events/com/oath/micro/server/MultiEventStatusResource.java similarity index 87% rename from micro-events/src/test/java/app/multi/events/com/aol/micro/server/MultiEventStatusResource.java rename to micro-events/src/test/java/app/multi/events/com/oath/micro/server/MultiEventStatusResource.java index d17675320..d0aa27fb2 100644 --- a/micro-events/src/test/java/app/multi/events/com/aol/micro/server/MultiEventStatusResource.java +++ b/micro-events/src/test/java/app/multi/events/com/oath/micro/server/MultiEventStatusResource.java @@ -1,4 +1,4 @@ -package app.multi.events.com.aol.micro.server; +package app.multi.events.com.oath.micro.server; import javax.ws.rs.GET; import javax.ws.rs.Path; @@ -7,8 +7,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import com.aol.micro.server.auto.discovery.RestResource; -import com.aol.micro.server.events.RequestEvents; +import com.oath.micro.server.auto.discovery.RestResource; +import com.oath.micro.server.events.RequestEvents; import com.google.common.eventbus.EventBus; @Component diff --git a/micro-events/src/test/java/app/multi/events/com/oath/micro/server/Schedular.java b/micro-events/src/test/java/app/multi/events/com/oath/micro/server/Schedular.java new file mode 100644 index 000000000..357becbef --- /dev/null +++ b/micro-events/src/test/java/app/multi/events/com/oath/micro/server/Schedular.java @@ -0,0 +1,21 @@ +package app.multi.events.com.oath.micro.server; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +@Component +public class Schedular { + + private final Job job; + + @Autowired + public Schedular(final Job job){ + this.job=job; + } + + @Scheduled(fixedDelay=1) + public synchronized void scheduleTask(){ + job.scheduleAndLog(); + } +} diff --git a/micro-events/src/test/java/com/aol/micro/server/testing/RestAgent.java b/micro-events/src/test/java/com/aol/micro/server/testing/RestAgent.java deleted file mode 100644 index ce204f810..000000000 --- a/micro-events/src/test/java/com/aol/micro/server/testing/RestAgent.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.aol.micro.server.testing; - -import java.util.List; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.Invocation.Builder; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; - -import com.aol.micro.server.rest.jackson.JacksonUtil; - -public class RestAgent { - - - public String getJson(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.get(String.class); - - } - - public String get(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.TEXT_PLAIN); - - return request.get(String.class); - - } - - public T post(String url, Object payload,Class type) { - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); - } - - -} diff --git a/micro-events/src/test/java/com/aol/micro/server/events/ActiveEventsTest.java b/micro-events/src/test/java/com/oath/micro/server/events/ActiveEventsTest.java similarity index 98% rename from micro-events/src/test/java/com/aol/micro/server/events/ActiveEventsTest.java rename to micro-events/src/test/java/com/oath/micro/server/events/ActiveEventsTest.java index a1047988f..7e35406ee 100644 --- a/micro-events/src/test/java/com/aol/micro/server/events/ActiveEventsTest.java +++ b/micro-events/src/test/java/com/oath/micro/server/events/ActiveEventsTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.events; +package com.oath.micro.server.events; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.is; diff --git a/micro-events/src/test/java/com/aol/micro/server/events/GenericEventTest.java b/micro-events/src/test/java/com/oath/micro/server/events/GenericEventTest.java similarity index 97% rename from micro-events/src/test/java/com/aol/micro/server/events/GenericEventTest.java rename to micro-events/src/test/java/com/oath/micro/server/events/GenericEventTest.java index 433991097..d2e3e63e1 100644 --- a/micro-events/src/test/java/com/aol/micro/server/events/GenericEventTest.java +++ b/micro-events/src/test/java/com/oath/micro/server/events/GenericEventTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.events; +package com.oath.micro.server.events; import com.google.common.eventbus.EventBus; import org.junit.Test; diff --git a/micro-events/src/test/java/com/aol/micro/server/events/JobNameTest.java b/micro-events/src/test/java/com/oath/micro/server/events/JobNameTest.java similarity index 83% rename from micro-events/src/test/java/com/aol/micro/server/events/JobNameTest.java rename to micro-events/src/test/java/com/oath/micro/server/events/JobNameTest.java index 933a08c68..87e3ffb9e 100644 --- a/micro-events/src/test/java/com/aol/micro/server/events/JobNameTest.java +++ b/micro-events/src/test/java/com/oath/micro/server/events/JobNameTest.java @@ -1,11 +1,11 @@ -package com.aol.micro.server.events; +package com.oath.micro.server.events; import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertThat; import org.junit.Test; -import com.aol.micro.server.events.JobName.Types; +import com.oath.micro.server.events.JobName.Types; public class JobNameTest { JobName simple = Types.SIMPLE.getCreator(); @@ -19,7 +19,7 @@ public void testSimple() { @Test public void testFull() { - assertThat(full.getType(JobNameTest.class), equalTo("com.aol.micro.server.events.JobNameTest")); + assertThat(full.getType(JobNameTest.class), equalTo("com.oath.micro.server.events.JobNameTest")); } @Test diff --git a/micro-events/src/test/java/com/aol/micro/server/events/JobsBeingExecutedTest.java b/micro-events/src/test/java/com/oath/micro/server/events/JobsBeingExecutedTest.java similarity index 99% rename from micro-events/src/test/java/com/aol/micro/server/events/JobsBeingExecutedTest.java rename to micro-events/src/test/java/com/oath/micro/server/events/JobsBeingExecutedTest.java index 9f3ddf024..5f79d9d34 100644 --- a/micro-events/src/test/java/com/aol/micro/server/events/JobsBeingExecutedTest.java +++ b/micro-events/src/test/java/com/oath/micro/server/events/JobsBeingExecutedTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.events; +package com.oath.micro.server.events; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; diff --git a/micro-events/src/test/java/com/aol/micro/server/events/LabelledEventsTest.java b/micro-events/src/test/java/com/oath/micro/server/events/LabelledEventsTest.java similarity index 86% rename from micro-events/src/test/java/com/aol/micro/server/events/LabelledEventsTest.java rename to micro-events/src/test/java/com/oath/micro/server/events/LabelledEventsTest.java index 421940ff9..3d34d84cb 100644 --- a/micro-events/src/test/java/com/aol/micro/server/events/LabelledEventsTest.java +++ b/micro-events/src/test/java/com/oath/micro/server/events/LabelledEventsTest.java @@ -1,11 +1,11 @@ -package com.aol.micro.server.events; +package com.oath.micro.server.events; import org.junit.Before; import org.junit.Test; -import com.aol.micro.server.events.RequestTypes.AddLabelledQuery; -import com.aol.micro.server.events.RequestTypes.RemoveLabelledQuery; -import com.aol.micro.server.events.RequestTypes.RequestData; +import com.oath.micro.server.events.RequestTypes.AddLabelledQuery; +import com.oath.micro.server.events.RequestTypes.RemoveLabelledQuery; +import com.oath.micro.server.events.RequestTypes.RequestData; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; diff --git a/micro-events/src/test/java/com/aol/micro/server/events/LoggingRateLimiterTest.java b/micro-events/src/test/java/com/oath/micro/server/events/LoggingRateLimiterTest.java similarity index 97% rename from micro-events/src/test/java/com/aol/micro/server/events/LoggingRateLimiterTest.java rename to micro-events/src/test/java/com/oath/micro/server/events/LoggingRateLimiterTest.java index 1dadcd6c1..d5dc14f91 100644 --- a/micro-events/src/test/java/com/aol/micro/server/events/LoggingRateLimiterTest.java +++ b/micro-events/src/test/java/com/oath/micro/server/events/LoggingRateLimiterTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.events; +package com.oath.micro.server.events; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; diff --git a/micro-events/src/test/java/com/aol/micro/server/events/RequestsBeingExecutedTest.java b/micro-events/src/test/java/com/oath/micro/server/events/RequestsBeingExecutedTest.java similarity index 98% rename from micro-events/src/test/java/com/aol/micro/server/events/RequestsBeingExecutedTest.java rename to micro-events/src/test/java/com/oath/micro/server/events/RequestsBeingExecutedTest.java index 763ce0870..245e48e28 100644 --- a/micro-events/src/test/java/com/aol/micro/server/events/RequestsBeingExecutedTest.java +++ b/micro-events/src/test/java/com/oath/micro/server/events/RequestsBeingExecutedTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.events; +package com.oath.micro.server.events; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.is; diff --git a/micro-events/src/test/java/com/aol/micro/server/rest/resources/ActiveResourceTest.java b/micro-events/src/test/java/com/oath/micro/server/rest/resources/ActiveResourceTest.java similarity index 89% rename from micro-events/src/test/java/com/aol/micro/server/rest/resources/ActiveResourceTest.java rename to micro-events/src/test/java/com/oath/micro/server/rest/resources/ActiveResourceTest.java index b03722183..afc30c027 100644 --- a/micro-events/src/test/java/com/aol/micro/server/rest/resources/ActiveResourceTest.java +++ b/micro-events/src/test/java/com/oath/micro/server/rest/resources/ActiveResourceTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.rest.resources; +package com.oath.micro.server.rest.resources; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; @@ -12,13 +12,13 @@ import org.junit.Before; import org.junit.Test; -import com.aol.micro.server.events.JobName; -import com.aol.micro.server.events.JobsBeingExecuted; -import com.aol.micro.server.events.RequestEvents; -import com.aol.micro.server.events.RequestTypes; -import com.aol.micro.server.events.RequestsBeingExecuted; -import com.aol.micro.server.events.ScheduledJob; -import com.aol.micro.server.rest.jackson.JacksonUtil; +import com.oath.micro.server.events.JobName; +import com.oath.micro.server.events.JobsBeingExecuted; +import com.oath.micro.server.events.RequestEvents; +import com.oath.micro.server.events.RequestTypes; +import com.oath.micro.server.events.RequestsBeingExecuted; +import com.oath.micro.server.events.ScheduledJob; +import com.oath.micro.server.rest.jackson.JacksonUtil; import com.google.common.collect.ImmutableMap; import com.google.common.eventbus.EventBus; diff --git a/micro-events/src/test/java/com/aol/micro/server/rest/resources/ManifestResourceTest.java b/micro-events/src/test/java/com/oath/micro/server/rest/resources/ManifestResourceTest.java similarity index 96% rename from micro-events/src/test/java/com/aol/micro/server/rest/resources/ManifestResourceTest.java rename to micro-events/src/test/java/com/oath/micro/server/rest/resources/ManifestResourceTest.java index 67c564b57..af1f6af4d 100644 --- a/micro-events/src/test/java/com/aol/micro/server/rest/resources/ManifestResourceTest.java +++ b/micro-events/src/test/java/com/oath/micro/server/rest/resources/ManifestResourceTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.rest.resources; +package com.oath.micro.server.rest.resources; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; diff --git a/micro-events/src/test/java/com/aol/micro/server/rest/resources/MockAsyncResponse.java b/micro-events/src/test/java/com/oath/micro/server/rest/resources/MockAsyncResponse.java similarity index 96% rename from micro-events/src/test/java/com/aol/micro/server/rest/resources/MockAsyncResponse.java rename to micro-events/src/test/java/com/oath/micro/server/rest/resources/MockAsyncResponse.java index 9412f05d4..4b0f63f42 100644 --- a/micro-events/src/test/java/com/aol/micro/server/rest/resources/MockAsyncResponse.java +++ b/micro-events/src/test/java/com/oath/micro/server/rest/resources/MockAsyncResponse.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.rest.resources; +package com.oath.micro.server.rest.resources; import java.util.Collection; import java.util.Date; @@ -9,8 +9,6 @@ import javax.ws.rs.container.AsyncResponse; import javax.ws.rs.container.TimeoutHandler; -import lombok.Getter; - public class MockAsyncResponse implements AsyncResponse { volatile Object response; diff --git a/micro-events/src/test/java/com/oath/micro/server/testing/RestAgent.java b/micro-events/src/test/java/com/oath/micro/server/testing/RestAgent.java new file mode 100644 index 000000000..b2b86303e --- /dev/null +++ b/micro-events/src/test/java/com/oath/micro/server/testing/RestAgent.java @@ -0,0 +1,53 @@ +package com.oath.micro.server.testing; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.Invocation.Builder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; + +import com.oath.micro.server.rest.jackson.JacksonUtil; + +public class RestAgent { + + + public String getJson(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.get(String.class); + + } + + public String get(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.TEXT_PLAIN); + + return request.get(String.class); + + } + + public T post(String url, Object payload,Class type) { + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); + } + + +} diff --git a/micro-general-exception-mapper/src/main/java/com/aol/micro/server/general/exception/mapper/ExceptionMapperPlugin.java b/micro-general-exception-mapper/src/main/java/com/aol/micro/server/general/exception/mapper/ExceptionMapperPlugin.java deleted file mode 100644 index 9f9c41348..000000000 --- a/micro-general-exception-mapper/src/main/java/com/aol/micro/server/general/exception/mapper/ExceptionMapperPlugin.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.aol.micro.server.general.exception.mapper; - -import java.util.HashSet; -import java.util.Set; - - -import com.aol.micro.server.Plugin; -import cyclops.collections.immutable.PersistentSetX; -import cyclops.collections.mutable.SetX; - -/** - * - * Collections of Spring configuration classes (Classes annotated with @Configuration) - * that configure various useful pieces of functionality - such as property file loading, - * datasources, scheduling etc - * - * @author johnmcclean - * - */ -public class ExceptionMapperPlugin implements Plugin{ - - @Override - public Set jaxRsPackages() { - return SetX.of("com.aol.micro.server.general.exception.mapper"); - - } - - @Override - public Set springClasses() { - return SetX.of(MapOfExceptionsToErrorCodes.class); - } - - - - - - -} diff --git a/micro-general-exception-mapper/src/main/java/com/oath/micro/server/general/exception/mapper/ExceptionMapperPlugin.java b/micro-general-exception-mapper/src/main/java/com/oath/micro/server/general/exception/mapper/ExceptionMapperPlugin.java new file mode 100644 index 000000000..20c1cf3fa --- /dev/null +++ b/micro-general-exception-mapper/src/main/java/com/oath/micro/server/general/exception/mapper/ExceptionMapperPlugin.java @@ -0,0 +1,36 @@ +package com.oath.micro.server.general.exception.mapper; + +import java.util.Set; + + +import com.oath.micro.server.Plugin; +import cyclops.collections.mutable.SetX; + +/** + * + * Collections of Spring configuration classes (Classes annotated with @Configuration) + * that configure various useful pieces of functionality - such as property file loading, + * datasources, scheduling etc + * + * @author johnmcclean + * + */ +public class ExceptionMapperPlugin implements Plugin{ + + @Override + public Set jaxRsPackages() { + return SetX.of("com.oath.micro.server.general.exception.mapper"); + + } + + @Override + public Set springClasses() { + return SetX.of(MapOfExceptionsToErrorCodes.class); + } + + + + + + +} diff --git a/micro-general-exception-mapper/src/main/java/com/aol/micro/server/general/exception/mapper/ExceptionWrapper.java b/micro-general-exception-mapper/src/main/java/com/oath/micro/server/general/exception/mapper/ExceptionWrapper.java similarity index 92% rename from micro-general-exception-mapper/src/main/java/com/aol/micro/server/general/exception/mapper/ExceptionWrapper.java rename to micro-general-exception-mapper/src/main/java/com/oath/micro/server/general/exception/mapper/ExceptionWrapper.java index 01fdd75b4..4dfde149c 100644 --- a/micro-general-exception-mapper/src/main/java/com/aol/micro/server/general/exception/mapper/ExceptionWrapper.java +++ b/micro-general-exception-mapper/src/main/java/com/oath/micro/server/general/exception/mapper/ExceptionWrapper.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.general.exception.mapper; +package com.oath.micro.server.general.exception.mapper; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/micro-general-exception-mapper/src/main/java/com/aol/micro/server/general/exception/mapper/ExtensionMapOfExceptionsToErrorCodes.java b/micro-general-exception-mapper/src/main/java/com/oath/micro/server/general/exception/mapper/ExtensionMapOfExceptionsToErrorCodes.java similarity index 93% rename from micro-general-exception-mapper/src/main/java/com/aol/micro/server/general/exception/mapper/ExtensionMapOfExceptionsToErrorCodes.java rename to micro-general-exception-mapper/src/main/java/com/oath/micro/server/general/exception/mapper/ExtensionMapOfExceptionsToErrorCodes.java index 5908817f2..416034f45 100644 --- a/micro-general-exception-mapper/src/main/java/com/aol/micro/server/general/exception/mapper/ExtensionMapOfExceptionsToErrorCodes.java +++ b/micro-general-exception-mapper/src/main/java/com/oath/micro/server/general/exception/mapper/ExtensionMapOfExceptionsToErrorCodes.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.general.exception.mapper; +package com.oath.micro.server.general.exception.mapper; import java.util.LinkedHashMap; diff --git a/micro-general-exception-mapper/src/main/java/com/aol/micro/server/general/exception/mapper/GeneralExceptionMapper.java b/micro-general-exception-mapper/src/main/java/com/oath/micro/server/general/exception/mapper/GeneralExceptionMapper.java similarity index 96% rename from micro-general-exception-mapper/src/main/java/com/aol/micro/server/general/exception/mapper/GeneralExceptionMapper.java rename to micro-general-exception-mapper/src/main/java/com/oath/micro/server/general/exception/mapper/GeneralExceptionMapper.java index e7a906fe3..b81fcce05 100644 --- a/micro-general-exception-mapper/src/main/java/com/aol/micro/server/general/exception/mapper/GeneralExceptionMapper.java +++ b/micro-general-exception-mapper/src/main/java/com/oath/micro/server/general/exception/mapper/GeneralExceptionMapper.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.general.exception.mapper; +package com.oath.micro.server.general.exception.mapper; @@ -13,7 +13,6 @@ import javax.ws.rs.ext.ExceptionMapper; import javax.ws.rs.ext.Provider; -import cyclops.data.tuple.Tuple; import cyclops.data.tuple.Tuple2; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/micro-general-exception-mapper/src/main/java/com/aol/micro/server/general/exception/mapper/MapOfExceptionsToErrorCodes.java b/micro-general-exception-mapper/src/main/java/com/oath/micro/server/general/exception/mapper/MapOfExceptionsToErrorCodes.java similarity index 97% rename from micro-general-exception-mapper/src/main/java/com/aol/micro/server/general/exception/mapper/MapOfExceptionsToErrorCodes.java rename to micro-general-exception-mapper/src/main/java/com/oath/micro/server/general/exception/mapper/MapOfExceptionsToErrorCodes.java index e20590f3f..bc39a9d0f 100644 --- a/micro-general-exception-mapper/src/main/java/com/aol/micro/server/general/exception/mapper/MapOfExceptionsToErrorCodes.java +++ b/micro-general-exception-mapper/src/main/java/com/oath/micro/server/general/exception/mapper/MapOfExceptionsToErrorCodes.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.general.exception.mapper; +package com.oath.micro.server.general.exception.mapper; import java.io.EOFException; import java.util.LinkedHashMap; diff --git a/micro-general-exception-mapper/src/main/resources/META-INF/services/com.aol.micro.server.Plugin b/micro-general-exception-mapper/src/main/resources/META-INF/services/com.aol.micro.server.Plugin deleted file mode 100644 index 90ea5c83c..000000000 --- a/micro-general-exception-mapper/src/main/resources/META-INF/services/com.aol.micro.server.Plugin +++ /dev/null @@ -1 +0,0 @@ -com.aol.micro.server.general.exception.mapper.ExceptionMapperPlugin \ No newline at end of file diff --git a/micro-general-exception-mapper/src/main/resources/META-INF/services/com.oath.micro.server.Plugin b/micro-general-exception-mapper/src/main/resources/META-INF/services/com.oath.micro.server.Plugin new file mode 100644 index 000000000..7d03f9d74 --- /dev/null +++ b/micro-general-exception-mapper/src/main/resources/META-INF/services/com.oath.micro.server.Plugin @@ -0,0 +1 @@ +com.oath.micro.server.general.exception.mapper.ExceptionMapperPlugin \ No newline at end of file diff --git a/micro-general-exception-mapper/src/test/java/app/custom/com/aol/micro/server/copy/CustomRunnerTest.java b/micro-general-exception-mapper/src/test/java/app/custom/com/aol/micro/server/copy/CustomRunnerTest.java deleted file mode 100644 index 28d1a7705..000000000 --- a/micro-general-exception-mapper/src/test/java/app/custom/com/aol/micro/server/copy/CustomRunnerTest.java +++ /dev/null @@ -1,54 +0,0 @@ -package app.custom.com.aol.micro.server.copy; - - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.Arrays; -import java.util.concurrent.ExecutionException; - -import org.glassfish.jersey.media.multipart.MultiPartFeature; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.testing.RestAgent; - -@Microserver -public class CustomRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer(){ - server = new MicroserverApp(ConfigurableModule - .builder() - .context("simple-app") - .defaultResources(Arrays.asList(MultiPartFeature.class)) - .build()); - - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - - assertThat(rest.get("http://localhost:8080/simple-app/status/ping").getStatus(),is(502)); - - - } - - - -} diff --git a/micro-general-exception-mapper/src/test/java/app/custom/com/aol/micro/server/copy/CustomStatusResource.java b/micro-general-exception-mapper/src/test/java/app/custom/com/aol/micro/server/copy/CustomStatusResource.java deleted file mode 100644 index 7bece4373..000000000 --- a/micro-general-exception-mapper/src/test/java/app/custom/com/aol/micro/server/copy/CustomStatusResource.java +++ /dev/null @@ -1,22 +0,0 @@ -package app.custom.com.aol.micro.server.copy; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; - - -import com.oath.cyclops.util.ExceptionSoftener; -import com.aol.micro.server.auto.discovery.Rest; - -@Rest -@Path("/status") -public class CustomStatusResource { - - @GET - @Path("/ping") - public String ping() { - throw ExceptionSoftener.throwSoftenedException( new MyException()); - - } - - -} \ No newline at end of file diff --git a/micro-general-exception-mapper/src/test/java/app/custom/com/aol/micro/server/copy/MyException.java b/micro-general-exception-mapper/src/test/java/app/custom/com/aol/micro/server/copy/MyException.java deleted file mode 100644 index 137bf5086..000000000 --- a/micro-general-exception-mapper/src/test/java/app/custom/com/aol/micro/server/copy/MyException.java +++ /dev/null @@ -1,5 +0,0 @@ -package app.custom.com.aol.micro.server.copy; - -public class MyException extends Exception { - -} diff --git a/micro-general-exception-mapper/src/test/java/app/custom/com/oath/micro/server/copy/CustomRunnerTest.java b/micro-general-exception-mapper/src/test/java/app/custom/com/oath/micro/server/copy/CustomRunnerTest.java new file mode 100644 index 000000000..011fa581b --- /dev/null +++ b/micro-general-exception-mapper/src/test/java/app/custom/com/oath/micro/server/copy/CustomRunnerTest.java @@ -0,0 +1,54 @@ +package app.custom.com.oath.micro.server.copy; + + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.Arrays; +import java.util.concurrent.ExecutionException; + +import org.glassfish.jersey.media.multipart.MultiPartFeature; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.module.ConfigurableModule; +import com.oath.micro.server.testing.RestAgent; + +@Microserver +public class CustomRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer(){ + server = new MicroserverApp(ConfigurableModule + .builder() + .context("simple-app") + .defaultResources(Arrays.asList(MultiPartFeature.class)) + .build()); + + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + + assertThat(rest.get("http://localhost:8080/simple-app/status/ping").getStatus(),is(502)); + + + } + + + +} diff --git a/micro-general-exception-mapper/src/test/java/app/custom/com/oath/micro/server/copy/CustomStatusResource.java b/micro-general-exception-mapper/src/test/java/app/custom/com/oath/micro/server/copy/CustomStatusResource.java new file mode 100644 index 000000000..d21b897ef --- /dev/null +++ b/micro-general-exception-mapper/src/test/java/app/custom/com/oath/micro/server/copy/CustomStatusResource.java @@ -0,0 +1,22 @@ +package app.custom.com.oath.micro.server.copy; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + + +import com.oath.cyclops.util.ExceptionSoftener; +import com.oath.micro.server.auto.discovery.Rest; + +@Rest +@Path("/status") +public class CustomStatusResource { + + @GET + @Path("/ping") + public String ping() { + throw ExceptionSoftener.throwSoftenedException( new MyException()); + + } + + +} \ No newline at end of file diff --git a/micro-general-exception-mapper/src/test/java/app/custom/com/aol/micro/server/copy/MappingExtension.java b/micro-general-exception-mapper/src/test/java/app/custom/com/oath/micro/server/copy/MappingExtension.java similarity index 80% rename from micro-general-exception-mapper/src/test/java/app/custom/com/aol/micro/server/copy/MappingExtension.java rename to micro-general-exception-mapper/src/test/java/app/custom/com/oath/micro/server/copy/MappingExtension.java index 154c1c5d8..9b7d152ac 100644 --- a/micro-general-exception-mapper/src/test/java/app/custom/com/aol/micro/server/copy/MappingExtension.java +++ b/micro-general-exception-mapper/src/test/java/app/custom/com/oath/micro/server/copy/MappingExtension.java @@ -1,4 +1,4 @@ -package app.custom.com.aol.micro.server.copy; +package app.custom.com.oath.micro.server.copy; import java.util.LinkedHashMap; @@ -8,7 +8,7 @@ import cyclops.data.tuple.Tuple2; import org.springframework.stereotype.Component; -import com.aol.micro.server.general.exception.mapper.ExtensionMapOfExceptionsToErrorCodes; +import com.oath.micro.server.general.exception.mapper.ExtensionMapOfExceptionsToErrorCodes; @Component public class MappingExtension implements ExtensionMapOfExceptionsToErrorCodes { diff --git a/micro-general-exception-mapper/src/test/java/app/custom/com/oath/micro/server/copy/MyException.java b/micro-general-exception-mapper/src/test/java/app/custom/com/oath/micro/server/copy/MyException.java new file mode 100644 index 000000000..18bd13624 --- /dev/null +++ b/micro-general-exception-mapper/src/test/java/app/custom/com/oath/micro/server/copy/MyException.java @@ -0,0 +1,5 @@ +package app.custom.com.oath.micro.server.copy; + +public class MyException extends Exception { + +} diff --git a/micro-general-exception-mapper/src/test/java/app/error/com/aol/micro/server/ErrorRunnerTest.java b/micro-general-exception-mapper/src/test/java/app/error/com/oath/micro/server/ErrorRunnerTest.java similarity index 78% rename from micro-general-exception-mapper/src/test/java/app/error/com/aol/micro/server/ErrorRunnerTest.java rename to micro-general-exception-mapper/src/test/java/app/error/com/oath/micro/server/ErrorRunnerTest.java index bc2e8da7d..1868126db 100644 --- a/micro-general-exception-mapper/src/test/java/app/error/com/aol/micro/server/ErrorRunnerTest.java +++ b/micro-general-exception-mapper/src/test/java/app/error/com/oath/micro/server/ErrorRunnerTest.java @@ -1,4 +1,4 @@ -package app.error.com.aol.micro.server; +package app.error.com.oath.micro.server; import static org.hamcrest.CoreMatchers.is; @@ -12,10 +12,10 @@ import org.junit.Before; import org.junit.Test; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.testing.RestAgent; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.module.ConfigurableModule; +import com.oath.micro.server.testing.RestAgent; @Microserver public class ErrorRunnerTest { diff --git a/micro-general-exception-mapper/src/test/java/app/error/com/aol/micro/server/ErrorStatusResource.java b/micro-general-exception-mapper/src/test/java/app/error/com/oath/micro/server/ErrorStatusResource.java similarity index 78% rename from micro-general-exception-mapper/src/test/java/app/error/com/aol/micro/server/ErrorStatusResource.java rename to micro-general-exception-mapper/src/test/java/app/error/com/oath/micro/server/ErrorStatusResource.java index 959b7795b..b32359827 100644 --- a/micro-general-exception-mapper/src/test/java/app/error/com/aol/micro/server/ErrorStatusResource.java +++ b/micro-general-exception-mapper/src/test/java/app/error/com/oath/micro/server/ErrorStatusResource.java @@ -1,4 +1,4 @@ -package app.error.com.aol.micro.server; +package app.error.com.oath.micro.server; import java.io.EOFException; @@ -7,7 +7,7 @@ import com.oath.cyclops.util.ExceptionSoftener; -import com.aol.micro.server.auto.discovery.Rest; +import com.oath.micro.server.auto.discovery.Rest; @Rest @Path("/status") diff --git a/micro-general-exception-mapper/src/test/java/com/aol/micro/server/general/exception/mapper/MyLocalException.java b/micro-general-exception-mapper/src/test/java/com/aol/micro/server/general/exception/mapper/MyLocalException.java deleted file mode 100644 index 95984f518..000000000 --- a/micro-general-exception-mapper/src/test/java/com/aol/micro/server/general/exception/mapper/MyLocalException.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.aol.micro.server.general.exception.mapper; - -public class MyLocalException extends Exception { - -} diff --git a/micro-general-exception-mapper/src/test/java/com/aol/micro/server/testing/RestAgent.java b/micro-general-exception-mapper/src/test/java/com/aol/micro/server/testing/RestAgent.java deleted file mode 100644 index eeaab558c..000000000 --- a/micro-general-exception-mapper/src/test/java/com/aol/micro/server/testing/RestAgent.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.aol.micro.server.testing; - -import java.util.List; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.Invocation.Builder; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import com.aol.micro.server.rest.jackson.JacksonUtil; - -public class RestAgent { - - - public Response get(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.get(); - - } - - - - -} diff --git a/micro-general-exception-mapper/src/test/java/com/aol/micro/server/general/exception/mapper/GeneralExceptionMapperTest.java b/micro-general-exception-mapper/src/test/java/com/oath/micro/server/general/exception/mapper/GeneralExceptionMapperTest.java similarity index 95% rename from micro-general-exception-mapper/src/test/java/com/aol/micro/server/general/exception/mapper/GeneralExceptionMapperTest.java rename to micro-general-exception-mapper/src/test/java/com/oath/micro/server/general/exception/mapper/GeneralExceptionMapperTest.java index d230bf54f..520ca443c 100644 --- a/micro-general-exception-mapper/src/test/java/com/aol/micro/server/general/exception/mapper/GeneralExceptionMapperTest.java +++ b/micro-general-exception-mapper/src/test/java/com/oath/micro/server/general/exception/mapper/GeneralExceptionMapperTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.general.exception.mapper; +package com.oath.micro.server.general.exception.mapper; import static org.hamcrest.Matchers.is; @@ -19,8 +19,6 @@ import org.junit.Test; import org.slf4j.Logger; -import app.custom.com.aol.micro.server.copy.MyException; - import com.fasterxml.jackson.core.JsonProcessingException; public class GeneralExceptionMapperTest { diff --git a/micro-general-exception-mapper/src/test/java/com/oath/micro/server/general/exception/mapper/MyLocalException.java b/micro-general-exception-mapper/src/test/java/com/oath/micro/server/general/exception/mapper/MyLocalException.java new file mode 100644 index 000000000..c4622989c --- /dev/null +++ b/micro-general-exception-mapper/src/test/java/com/oath/micro/server/general/exception/mapper/MyLocalException.java @@ -0,0 +1,5 @@ +package com.oath.micro.server.general.exception.mapper; + +public class MyLocalException extends Exception { + +} diff --git a/micro-general-exception-mapper/src/test/java/com/oath/micro/server/testing/RestAgent.java b/micro-general-exception-mapper/src/test/java/com/oath/micro/server/testing/RestAgent.java new file mode 100644 index 000000000..3749ecb41 --- /dev/null +++ b/micro-general-exception-mapper/src/test/java/com/oath/micro/server/testing/RestAgent.java @@ -0,0 +1,29 @@ +package com.oath.micro.server.testing; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Invocation.Builder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +public class RestAgent { + + + public Response get(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.get(); + + } + + + + +} diff --git a/micro-grizzly-with-jersey/src/test/java/app/async/com/aol/micro/server/AsyncAppRunner.java b/micro-grizzly-with-jersey/src/test/java/app/async/com/aol/micro/server/AsyncAppRunner.java deleted file mode 100644 index 979b5fbf5..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/async/com/aol/micro/server/AsyncAppRunner.java +++ /dev/null @@ -1,57 +0,0 @@ -package app.async.com.aol.micro.server; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.io.IOException; -import java.util.Properties; -import java.util.concurrent.ExecutionException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.spring.properties.PropertyFileConfig; -import com.aol.micro.server.testing.RestAgent; - -@Microserver -public class AsyncAppRunner { - - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer(){ - - server = new MicroserverApp( ()-> "async-app"); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - Thread.sleep(2000); - - assertThat(rest.get("http://localhost:8080/async-app/async/expensive"),is(";test!;test!;test!")); - - } - - @Test - public void loadProperties() throws IOException{ - - Properties props = new PropertyFileConfig(true).propertyFactory() ; - assertThat(props.getProperty("test"),is("hello world")); - } - - - -} \ No newline at end of file diff --git a/micro-grizzly-with-jersey/src/test/java/app/async/com/aol/micro/server/AsyncResource.java b/micro-grizzly-with-jersey/src/test/java/app/async/com/aol/micro/server/AsyncResource.java deleted file mode 100644 index 34f8f0079..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/async/com/aol/micro/server/AsyncResource.java +++ /dev/null @@ -1,57 +0,0 @@ -package app.async.com.aol.micro.server; - -import java.util.Arrays; -import java.util.List; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.container.AsyncResponse; -import javax.ws.rs.container.Suspended; - -import cyclops.async.SimpleReact; -import cyclops.reactive.FutureStream; -import cyclops.reactive.ReactiveSeq; -import org.springframework.stereotype.Component; - - -import com.aol.micro.server.auto.discovery.RestResource; -import com.aol.micro.server.testing.RestAgent; - -@Path("/async") -@Component -public class AsyncResource implements RestResource{ - - private final SimpleReact simpleReact =new SimpleReact(); - private final List urls = Arrays.asList("http://localhost:8080/async-app/async/ping2", - "http://localhost:8080/async-app/async/ping", - "http://localhost:8080/async-app/async/ping", - "http://localhost:8080/async-app/async/ping"); - - private final RestAgent client = new RestAgent(); - - @GET - @Path("/expensive") - @Produces("text/plain") - public void expensive(@Suspended AsyncResponse asyncResponse){ - - FutureStream.builder().fromIterable(urls) - .then(it->client.get(it)) - .onFail(it -> "") - .peek(it -> - System.out.println(it)) - .convertToSimpleReact() - .allOf(data -> { - System.out.println(data); - return asyncResponse.resume(ReactiveSeq.fromIterable(data).join(";")); }); - } - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "test!"; - } - - -} diff --git a/micro-grizzly-with-jersey/src/test/java/app/async/com/aol/micro/server/Simple.java b/micro-grizzly-with-jersey/src/test/java/app/async/com/aol/micro/server/Simple.java deleted file mode 100644 index edefa80ef..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/async/com/aol/micro/server/Simple.java +++ /dev/null @@ -1,16 +0,0 @@ -package app.async.com.aol.micro.server; - -import java.io.IOException; -import java.util.Properties; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Config; -import com.aol.micro.server.spring.properties.PropertyFileConfig; - -public class Simple { - - public static void main(String[] args) throws IOException{ - - new MicroserverApp(()->"test-app").run(); - } -} diff --git a/micro-grizzly-with-jersey/src/test/java/app/async/com/aol/micro/server/SimpleApp.java b/micro-grizzly-with-jersey/src/test/java/app/async/com/aol/micro/server/SimpleApp.java deleted file mode 100644 index 919b7c6b0..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/async/com/aol/micro/server/SimpleApp.java +++ /dev/null @@ -1,24 +0,0 @@ -package app.async.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.Rest; - - - -@Rest -@Path("/test") -public class SimpleApp { - - public static void main(String[] args){ - new MicroserverApp(()->"test-app").run(); - } - @GET - public String myEndPoint(){ - return "hello world!"; - } - - -} diff --git a/micro-grizzly-with-jersey/src/test/java/app/async/com/oath/micro/server/AsyncAppRunner.java b/micro-grizzly-with-jersey/src/test/java/app/async/com/oath/micro/server/AsyncAppRunner.java new file mode 100644 index 000000000..c71dd8184 --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/async/com/oath/micro/server/AsyncAppRunner.java @@ -0,0 +1,57 @@ +package app.async.com.oath.micro.server; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.io.IOException; +import java.util.Properties; +import java.util.concurrent.ExecutionException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.spring.properties.PropertyFileConfig; +import com.oath.micro.server.testing.RestAgent; + +@Microserver +public class AsyncAppRunner { + + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer(){ + + server = new MicroserverApp( ()-> "async-app"); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + Thread.sleep(2000); + + assertThat(rest.get("http://localhost:8080/async-app/async/expensive"),is(";test!;test!;test!")); + + } + + @Test + public void loadProperties() throws IOException{ + + Properties props = new PropertyFileConfig(true).propertyFactory() ; + assertThat(props.getProperty("test"),is("hello world")); + } + + + +} \ No newline at end of file diff --git a/micro-grizzly-with-jersey/src/test/java/app/async/com/oath/micro/server/AsyncResource.java b/micro-grizzly-with-jersey/src/test/java/app/async/com/oath/micro/server/AsyncResource.java new file mode 100644 index 000000000..3d230ee9b --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/async/com/oath/micro/server/AsyncResource.java @@ -0,0 +1,57 @@ +package app.async.com.oath.micro.server; + +import java.util.Arrays; +import java.util.List; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.container.AsyncResponse; +import javax.ws.rs.container.Suspended; + +import cyclops.async.SimpleReact; +import cyclops.reactive.FutureStream; +import cyclops.reactive.ReactiveSeq; +import org.springframework.stereotype.Component; + + +import com.oath.micro.server.auto.discovery.RestResource; +import com.oath.micro.server.testing.RestAgent; + +@Path("/async") +@Component +public class AsyncResource implements RestResource{ + + private final SimpleReact simpleReact =new SimpleReact(); + private final List urls = Arrays.asList("http://localhost:8080/async-app/async/ping2", + "http://localhost:8080/async-app/async/ping", + "http://localhost:8080/async-app/async/ping", + "http://localhost:8080/async-app/async/ping"); + + private final RestAgent client = new RestAgent(); + + @GET + @Path("/expensive") + @Produces("text/plain") + public void expensive(@Suspended AsyncResponse asyncResponse){ + + FutureStream.builder().fromIterable(urls) + .then(it->client.get(it)) + .onFail(it -> "") + .peek(it -> + System.out.println(it)) + .convertToSimpleReact() + .allOf(data -> { + System.out.println(data); + return asyncResponse.resume(ReactiveSeq.fromIterable(data).join(";")); }); + } + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "test!"; + } + + +} diff --git a/micro-grizzly-with-jersey/src/test/java/app/async/com/oath/micro/server/Simple.java b/micro-grizzly-with-jersey/src/test/java/app/async/com/oath/micro/server/Simple.java new file mode 100644 index 000000000..3eb3e7504 --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/async/com/oath/micro/server/Simple.java @@ -0,0 +1,13 @@ +package app.async.com.oath.micro.server; + +import java.io.IOException; + +import com.oath.micro.server.MicroserverApp; + +public class Simple { + + public static void main(String[] args) throws IOException{ + + new MicroserverApp(()->"test-app").run(); + } +} diff --git a/micro-grizzly-with-jersey/src/test/java/app/async/com/oath/micro/server/SimpleApp.java b/micro-grizzly-with-jersey/src/test/java/app/async/com/oath/micro/server/SimpleApp.java new file mode 100644 index 000000000..916d0330e --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/async/com/oath/micro/server/SimpleApp.java @@ -0,0 +1,24 @@ +package app.async.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.auto.discovery.Rest; + + + +@Rest +@Path("/test") +public class SimpleApp { + + public static void main(String[] args){ + new MicroserverApp(()->"test-app").run(); + } + @GET + public String myEndPoint(){ + return "hello world!"; + } + + +} diff --git a/micro-grizzly-with-jersey/src/test/java/app/blacklisted/com/aol/micro/server/copy/SimpleApp.java b/micro-grizzly-with-jersey/src/test/java/app/blacklisted/com/aol/micro/server/copy/SimpleApp.java deleted file mode 100644 index 37a92de67..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/blacklisted/com/aol/micro/server/copy/SimpleApp.java +++ /dev/null @@ -1,18 +0,0 @@ -package app.blacklisted.com.aol.micro.server.copy; - -import java.util.Arrays; - -import org.glassfish.jersey.media.multipart.MultiPartFeature; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.module.ConfigurableModule; - -public class SimpleApp { - - public static void main(String[] args){ - - new MicroserverApp(()-> "simple-app").run(); - } - - -} diff --git a/micro-grizzly-with-jersey/src/test/java/app/blacklisted/com/aol/micro/server/copy/SimpleRunnerTest.java b/micro-grizzly-with-jersey/src/test/java/app/blacklisted/com/aol/micro/server/copy/SimpleRunnerTest.java deleted file mode 100644 index 8f677b7fd..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/blacklisted/com/aol/micro/server/copy/SimpleRunnerTest.java +++ /dev/null @@ -1,57 +0,0 @@ -package app.blacklisted.com.aol.micro.server.copy; - - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.Arrays; -import java.util.concurrent.ExecutionException; - -import nonautoscan.com.aol.micro.server.ScheduleAndAsyncConfig; - -import org.glassfish.jersey.media.multipart.MultiPartFeature; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.testing.RestAgent; - -@Microserver(blacklistedClasses={ScheduleAndAsyncConfig.class}) -public class SimpleRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer(){ - server = new MicroserverApp(ConfigurableModule - .builder() - .context("simple-app") - .defaultResources(Arrays.asList(MultiPartFeature.class)) - .build()); - - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - - - assertThat(rest.get("http://localhost:8080/simple-app/status/ping"),is("ok")); - - - } - - - -} diff --git a/micro-grizzly-with-jersey/src/test/java/app/blacklisted/com/aol/micro/server/copy/SimpleStatusResource.java b/micro-grizzly-with-jersey/src/test/java/app/blacklisted/com/aol/micro/server/copy/SimpleStatusResource.java deleted file mode 100644 index 3ad8426ad..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/blacklisted/com/aol/micro/server/copy/SimpleStatusResource.java +++ /dev/null @@ -1,53 +0,0 @@ -package app.blacklisted.com.aol.micro.server.copy; - -import java.io.InputStream; - -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; - -import nonautoscan.com.aol.micro.server.ScheduleAndAsyncConfig; - -import org.glassfish.jersey.media.multipart.FormDataContentDisposition; -import org.glassfish.jersey.media.multipart.FormDataParam; -import org.junit.Assert; -import org.springframework.beans.factory.NoSuchBeanDefinitionException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; - -import com.aol.micro.server.auto.discovery.Rest; - -@Rest -@Path("/status") -public class SimpleStatusResource { - - @Autowired - ApplicationContext context; - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - - try{ - context.getBean(ScheduleAndAsyncConfig.class); - Assert.fail("failed to remove ScheduleAndAsyncConfig bean!"); - }catch(NoSuchBeanDefinitionException e){ - - } - return "ok"; - } - - @POST - @Consumes(MediaType.MULTIPART_FORM_DATA) - @Produces(MediaType.TEXT_PLAIN) - @Path("/file") - public String create( - @FormDataParam("file") InputStream fileInputStream, - @FormDataParam("file") FormDataContentDisposition contentDispositionHeader) { - - return "done"; - } -} \ No newline at end of file diff --git a/micro-grizzly-with-jersey/src/test/java/app/blacklisted/com/oath/micro/server/copy/SimpleApp.java b/micro-grizzly-with-jersey/src/test/java/app/blacklisted/com/oath/micro/server/copy/SimpleApp.java new file mode 100644 index 000000000..f73582b0c --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/blacklisted/com/oath/micro/server/copy/SimpleApp.java @@ -0,0 +1,13 @@ +package app.blacklisted.com.oath.micro.server.copy; + +import com.oath.micro.server.MicroserverApp; + +public class SimpleApp { + + public static void main(String[] args){ + + new MicroserverApp(()-> "simple-app").run(); + } + + +} diff --git a/micro-grizzly-with-jersey/src/test/java/app/blacklisted/com/oath/micro/server/copy/SimpleRunnerTest.java b/micro-grizzly-with-jersey/src/test/java/app/blacklisted/com/oath/micro/server/copy/SimpleRunnerTest.java new file mode 100644 index 000000000..ebdee84f1 --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/blacklisted/com/oath/micro/server/copy/SimpleRunnerTest.java @@ -0,0 +1,57 @@ +package app.blacklisted.com.oath.micro.server.copy; + + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.Arrays; +import java.util.concurrent.ExecutionException; + +import nonautoscan.com.oath.micro.server.ScheduleAndAsyncConfig; + +import org.glassfish.jersey.media.multipart.MultiPartFeature; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.module.ConfigurableModule; +import com.oath.micro.server.testing.RestAgent; + +@Microserver(blacklistedClasses={ScheduleAndAsyncConfig.class}) +public class SimpleRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer(){ + server = new MicroserverApp(ConfigurableModule + .builder() + .context("simple-app") + .defaultResources(Arrays.asList(MultiPartFeature.class)) + .build()); + + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + + + assertThat(rest.get("http://localhost:8080/simple-app/status/ping"),is("ok")); + + + } + + + +} diff --git a/micro-grizzly-with-jersey/src/test/java/app/blacklisted/com/oath/micro/server/copy/SimpleStatusResource.java b/micro-grizzly-with-jersey/src/test/java/app/blacklisted/com/oath/micro/server/copy/SimpleStatusResource.java new file mode 100644 index 000000000..4370e7e9a --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/blacklisted/com/oath/micro/server/copy/SimpleStatusResource.java @@ -0,0 +1,53 @@ +package app.blacklisted.com.oath.micro.server.copy; + +import java.io.InputStream; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +import nonautoscan.com.oath.micro.server.ScheduleAndAsyncConfig; + +import org.glassfish.jersey.media.multipart.FormDataContentDisposition; +import org.glassfish.jersey.media.multipart.FormDataParam; +import org.junit.Assert; +import org.springframework.beans.factory.NoSuchBeanDefinitionException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; + +import com.oath.micro.server.auto.discovery.Rest; + +@Rest +@Path("/status") +public class SimpleStatusResource { + + @Autowired + ApplicationContext context; + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + + try{ + context.getBean(ScheduleAndAsyncConfig.class); + Assert.fail("failed to remove ScheduleAndAsyncConfig bean!"); + }catch(NoSuchBeanDefinitionException e){ + + } + return "ok"; + } + + @POST + @Consumes(MediaType.MULTIPART_FORM_DATA) + @Produces(MediaType.TEXT_PLAIN) + @Path("/file") + public String create( + @FormDataParam("file") InputStream fileInputStream, + @FormDataParam("file") FormDataContentDisposition contentDispositionHeader) { + + return "done"; + } +} \ No newline at end of file diff --git a/micro-grizzly-with-jersey/src/test/java/app/custom/binder/direct/BinderDirectTest.java b/micro-grizzly-with-jersey/src/test/java/app/custom/binder/direct/BinderDirectTest.java index 5a8cf0fd2..192708053 100644 --- a/micro-grizzly-with-jersey/src/test/java/app/custom/binder/direct/BinderDirectTest.java +++ b/micro-grizzly-with-jersey/src/test/java/app/custom/binder/direct/BinderDirectTest.java @@ -12,11 +12,10 @@ import org.junit.Test; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.module.Module; -import com.aol.micro.server.testing.RestAgent; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.module.ConfigurableModule; +import com.oath.micro.server.testing.RestAgent; @Microserver public class BinderDirectTest { diff --git a/micro-grizzly-with-jersey/src/test/java/app/custom/binder/direct/CustomBinder4.java b/micro-grizzly-with-jersey/src/test/java/app/custom/binder/direct/CustomBinder4.java index 9c2b15310..1cd4458e0 100644 --- a/micro-grizzly-with-jersey/src/test/java/app/custom/binder/direct/CustomBinder4.java +++ b/micro-grizzly-with-jersey/src/test/java/app/custom/binder/direct/CustomBinder4.java @@ -2,8 +2,6 @@ import org.glassfish.hk2.utilities.binding.AbstractBinder; import org.glassfish.jersey.server.spi.internal.ResourceMethodInvocationHandlerProvider; -import com.aol.micro.server.auto.discovery.JaxRsResource; - public class CustomBinder4 extends AbstractBinder { @Override diff --git a/micro-grizzly-with-jersey/src/test/java/app/custom/binder/direct/SimpleApp.java b/micro-grizzly-with-jersey/src/test/java/app/custom/binder/direct/SimpleApp.java index 95150b9e9..b909890af 100644 --- a/micro-grizzly-with-jersey/src/test/java/app/custom/binder/direct/SimpleApp.java +++ b/micro-grizzly-with-jersey/src/test/java/app/custom/binder/direct/SimpleApp.java @@ -3,12 +3,7 @@ import javax.ws.rs.GET; import javax.ws.rs.Path; -import org.glassfish.jersey.server.ResourceConfig; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.module.ConfigurableModule; - +import com.oath.micro.server.auto.discovery.Rest; @Rest diff --git a/micro-grizzly-with-jersey/src/test/java/app/custom/binder/noanno/BinderTest.java b/micro-grizzly-with-jersey/src/test/java/app/custom/binder/noanno/BinderTest.java index 9b8648497..0f57e40ab 100644 --- a/micro-grizzly-with-jersey/src/test/java/app/custom/binder/noanno/BinderTest.java +++ b/micro-grizzly-with-jersey/src/test/java/app/custom/binder/noanno/BinderTest.java @@ -10,9 +10,9 @@ import org.junit.Before; import org.junit.Test; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.testing.RestAgent; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.testing.RestAgent; @Microserver public class BinderTest { diff --git a/micro-grizzly-with-jersey/src/test/java/app/custom/binder/noanno/Config.java b/micro-grizzly-with-jersey/src/test/java/app/custom/binder/noanno/Config.java index 024b965a7..3bafd3e1b 100644 --- a/micro-grizzly-with-jersey/src/test/java/app/custom/binder/noanno/Config.java +++ b/micro-grizzly-with-jersey/src/test/java/app/custom/binder/noanno/Config.java @@ -3,7 +3,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import com.aol.micro.server.auto.discovery.JaxRsResourceWrapper; +import com.oath.micro.server.auto.discovery.JaxRsResourceWrapper; @Configuration public class Config { diff --git a/micro-grizzly-with-jersey/src/test/java/app/custom/binder/noanno/CustomBinder2.java b/micro-grizzly-with-jersey/src/test/java/app/custom/binder/noanno/CustomBinder2.java index e42284b21..706ab300e 100644 --- a/micro-grizzly-with-jersey/src/test/java/app/custom/binder/noanno/CustomBinder2.java +++ b/micro-grizzly-with-jersey/src/test/java/app/custom/binder/noanno/CustomBinder2.java @@ -2,8 +2,6 @@ import org.glassfish.hk2.utilities.binding.AbstractBinder; import org.glassfish.jersey.server.spi.internal.ResourceMethodInvocationHandlerProvider; -import com.aol.micro.server.auto.discovery.JaxRsResource; - public class CustomBinder2 extends AbstractBinder { @Override diff --git a/micro-grizzly-with-jersey/src/test/java/app/custom/binder/noanno/SimpleApp.java b/micro-grizzly-with-jersey/src/test/java/app/custom/binder/noanno/SimpleApp.java index bfa784520..62668fa46 100644 --- a/micro-grizzly-with-jersey/src/test/java/app/custom/binder/noanno/SimpleApp.java +++ b/micro-grizzly-with-jersey/src/test/java/app/custom/binder/noanno/SimpleApp.java @@ -3,12 +3,7 @@ import javax.ws.rs.GET; import javax.ws.rs.Path; -import org.glassfish.jersey.server.ResourceConfig; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.module.ConfigurableModule; - +import com.oath.micro.server.auto.discovery.Rest; @Rest diff --git a/micro-grizzly-with-jersey/src/test/java/app/custom/binder/resource/objects/BinderTest.java b/micro-grizzly-with-jersey/src/test/java/app/custom/binder/resource/objects/BinderTest.java index 9d650b19e..1538d7856 100644 --- a/micro-grizzly-with-jersey/src/test/java/app/custom/binder/resource/objects/BinderTest.java +++ b/micro-grizzly-with-jersey/src/test/java/app/custom/binder/resource/objects/BinderTest.java @@ -6,18 +6,16 @@ import java.util.concurrent.ExecutionException; -import cyclops.collections.immutable.PersistentSetX; import cyclops.collections.mutable.SetX; import org.junit.After; import org.junit.Before; import org.junit.Test; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.module.Module; -import com.aol.micro.server.testing.RestAgent; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.module.ConfigurableModule; +import com.oath.micro.server.testing.RestAgent; @Microserver public class BinderTest { diff --git a/micro-grizzly-with-jersey/src/test/java/app/custom/binder/resource/objects/CustomBinder3.java b/micro-grizzly-with-jersey/src/test/java/app/custom/binder/resource/objects/CustomBinder3.java index b10bf9ce1..c08aed638 100644 --- a/micro-grizzly-with-jersey/src/test/java/app/custom/binder/resource/objects/CustomBinder3.java +++ b/micro-grizzly-with-jersey/src/test/java/app/custom/binder/resource/objects/CustomBinder3.java @@ -2,8 +2,6 @@ import org.glassfish.hk2.utilities.binding.AbstractBinder; import org.glassfish.jersey.server.spi.internal.ResourceMethodInvocationHandlerProvider; -import com.aol.micro.server.auto.discovery.JaxRsResource; - public class CustomBinder3 extends AbstractBinder { @Override diff --git a/micro-grizzly-with-jersey/src/test/java/app/custom/binder/resource/objects/SimpleApp.java b/micro-grizzly-with-jersey/src/test/java/app/custom/binder/resource/objects/SimpleApp.java index 84728cf63..36a9da879 100644 --- a/micro-grizzly-with-jersey/src/test/java/app/custom/binder/resource/objects/SimpleApp.java +++ b/micro-grizzly-with-jersey/src/test/java/app/custom/binder/resource/objects/SimpleApp.java @@ -3,12 +3,7 @@ import javax.ws.rs.GET; import javax.ws.rs.Path; -import org.glassfish.jersey.server.ResourceConfig; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.module.ConfigurableModule; - +import com.oath.micro.server.auto.discovery.Rest; @Rest diff --git a/micro-grizzly-with-jersey/src/test/java/app/custom/binder/test/BinderTest.java b/micro-grizzly-with-jersey/src/test/java/app/custom/binder/test/BinderTest.java index 76c4d7950..5fcb95fc1 100644 --- a/micro-grizzly-with-jersey/src/test/java/app/custom/binder/test/BinderTest.java +++ b/micro-grizzly-with-jersey/src/test/java/app/custom/binder/test/BinderTest.java @@ -3,18 +3,15 @@ import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.*; -import java.util.Arrays; import java.util.concurrent.ExecutionException; -import org.glassfish.jersey.media.multipart.MultiPartFeature; import org.junit.After; import org.junit.Before; import org.junit.Test; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.testing.RestAgent; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.testing.RestAgent; @Microserver public class BinderTest { diff --git a/micro-grizzly-with-jersey/src/test/java/app/custom/binder/test/CustomBinder.java b/micro-grizzly-with-jersey/src/test/java/app/custom/binder/test/CustomBinder.java index 0e23b79a7..299a46bf4 100644 --- a/micro-grizzly-with-jersey/src/test/java/app/custom/binder/test/CustomBinder.java +++ b/micro-grizzly-with-jersey/src/test/java/app/custom/binder/test/CustomBinder.java @@ -2,7 +2,7 @@ import org.glassfish.hk2.utilities.binding.AbstractBinder; import org.glassfish.jersey.server.spi.internal.ResourceMethodInvocationHandlerProvider; -import com.aol.micro.server.auto.discovery.JaxRsResource; +import com.oath.micro.server.auto.discovery.JaxRsResource; @JaxRsResource public class CustomBinder extends AbstractBinder { diff --git a/micro-grizzly-with-jersey/src/test/java/app/custom/binder/test/SimpleApp.java b/micro-grizzly-with-jersey/src/test/java/app/custom/binder/test/SimpleApp.java index 7a2c74e08..2e275f0bd 100644 --- a/micro-grizzly-with-jersey/src/test/java/app/custom/binder/test/SimpleApp.java +++ b/micro-grizzly-with-jersey/src/test/java/app/custom/binder/test/SimpleApp.java @@ -5,9 +5,9 @@ import org.glassfish.jersey.server.ResourceConfig; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.module.ConfigurableModule; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.auto.discovery.Rest; +import com.oath.micro.server.module.ConfigurableModule; diff --git a/micro-grizzly-with-jersey/src/test/java/app/embedded/com/aol/micro/server/AltAppResource.java b/micro-grizzly-with-jersey/src/test/java/app/embedded/com/aol/micro/server/AltAppResource.java deleted file mode 100644 index d4b8eff5c..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/embedded/com/aol/micro/server/AltAppResource.java +++ /dev/null @@ -1,23 +0,0 @@ -package app.embedded.com.aol.micro.server; - -import java.util.ArrayList; -import java.util.List; - -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.stereotype.Component; - -@Component -@Path("/alt-status") -public class AltAppResource implements AltAppRestResource { - - @POST - @Produces("application/json") - @Path("/ping") - public List ping(ImmutableEntity entity) { - return entity.getList(); - } - -} diff --git a/micro-grizzly-with-jersey/src/test/java/app/embedded/com/aol/micro/server/AltAppRestResource.java b/micro-grizzly-with-jersey/src/test/java/app/embedded/com/aol/micro/server/AltAppRestResource.java deleted file mode 100644 index 8cb2643e3..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/embedded/com/aol/micro/server/AltAppRestResource.java +++ /dev/null @@ -1,7 +0,0 @@ -package app.embedded.com.aol.micro.server; - -import com.aol.micro.server.auto.discovery.RestResource; - -public interface AltAppRestResource extends RestResource { - -} diff --git a/micro-grizzly-with-jersey/src/test/java/app/embedded/com/aol/micro/server/EmbeddedAppLocalMain.java b/micro-grizzly-with-jersey/src/test/java/app/embedded/com/aol/micro/server/EmbeddedAppLocalMain.java deleted file mode 100644 index bc73c2862..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/embedded/com/aol/micro/server/EmbeddedAppLocalMain.java +++ /dev/null @@ -1,24 +0,0 @@ -package app.embedded.com.aol.micro.server; - -import java.util.Arrays; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.module.EmbeddedModule; - -@Microserver(basePackages = { "app.embedded.com.aol.micro.server" }) -public class EmbeddedAppLocalMain { - - - public static void main(String[] args) throws InterruptedException { - - new MicroserverApp( - EmbeddedModule.tagInterfaceModule(Arrays.asList(TestAppRestResource.class),"test-app"), - EmbeddedModule.tagInterfaceModule(Arrays.asList(AltAppRestResource.class),"alternative-app")).start(); - - - - } - - -} diff --git a/micro-grizzly-with-jersey/src/test/java/app/embedded/com/aol/micro/server/EmbeddedAppTest.java b/micro-grizzly-with-jersey/src/test/java/app/embedded/com/aol/micro/server/EmbeddedAppTest.java deleted file mode 100644 index 47228dc0b..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/embedded/com/aol/micro/server/EmbeddedAppTest.java +++ /dev/null @@ -1,102 +0,0 @@ -package app.embedded.com.aol.micro.server; - -import static org.hamcrest.Matchers.hasItem; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; - -import javax.ws.rs.NotFoundException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.springframework.util.concurrent.ListenableFuture; -import org.springframework.util.concurrent.ListenableFutureCallback; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.module.EmbeddedModule; -import com.aol.micro.server.testing.RestAgent; - -public class EmbeddedAppTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - - @Before - public void startServer(){ - server = new MicroserverApp(EmbeddedAppLocalMain.class, - EmbeddedModule.tagInterfaceModule(Arrays.asList(TestAppRestResource.class),"test-app"), - EmbeddedModule.tagInterfaceModule(Arrays.asList(AltAppRestResource.class),"alternative-app")); - server.start(); - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void confirmExpectedUrlsPresentTest() throws InterruptedException, ExecutionException{ - - assertThat(rest.get("http://localhost:8080/test-app/test-status/ping"),is("test!")); - - - assertThat((List)rest.post("http://localhost:8081/alternative-app/alt-status/ping",new ImmutableEntity("value",Arrays.asList("hello","world")),List.class), - hasItem("hello")); - - } - - - @Test - public void nonBlockingRestClientTest(){ - assertThat(rest.get("http://localhost:8080/test-app/test-status/rest-calls"),is("-*test!-*test!")); - } - - CompletableFuture toCompletableFuture( - final ListenableFuture listenableFuture - ) { - //create an instance of CompletableFuture - CompletableFuture completable = new CompletableFuture() { - @Override - public boolean cancel(boolean mayInterruptIfRunning) { - // propagate cancel to the listenable future - boolean result = listenableFuture.cancel(mayInterruptIfRunning); - super.cancel(mayInterruptIfRunning); - return result; - } - }; - - // add callback - listenableFuture.addCallback(new ListenableFutureCallback() { - @Override - public void onSuccess(T result) { - completable.complete(result); - } - - @Override - public void onFailure(Throwable t) { - completable.completeExceptionally(t); - } - }); - return completable; - } - - @Test(expected=NotFoundException.class) - public void confirmAltAppCantUseTestAppResources(){ - - assertThat(rest.get("http://localhost:8080/alternative-app/test-status/ping"),is("test!")); - - } - @Test(expected=NotFoundException.class) - public void confirmTestAppCantUseAltAppResources(){ - - assertThat((List)rest.post("http://localhost:8081/test-app/alt-status/ping",new ImmutableEntity("value",Arrays.asList("hello","world")),List.class), - hasItem("hello")); - - } -} diff --git a/micro-grizzly-with-jersey/src/test/java/app/embedded/com/aol/micro/server/ImmutableEntity.java b/micro-grizzly-with-jersey/src/test/java/app/embedded/com/aol/micro/server/ImmutableEntity.java deleted file mode 100644 index cd593f123..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/embedded/com/aol/micro/server/ImmutableEntity.java +++ /dev/null @@ -1,29 +0,0 @@ -package app.embedded.com.aol.micro.server; - -import java.util.List; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Builder; - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "") -@XmlRootElement(name = "immutable") -@Getter -@AllArgsConstructor -@Builder -public class ImmutableEntity { - - private final String value; - private final List list; - - public ImmutableEntity() { - this(null,null); - } - -} diff --git a/micro-grizzly-with-jersey/src/test/java/app/embedded/com/aol/micro/server/TestAppResource.java b/micro-grizzly-with-jersey/src/test/java/app/embedded/com/aol/micro/server/TestAppResource.java deleted file mode 100644 index 24c0ebe27..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/embedded/com/aol/micro/server/TestAppResource.java +++ /dev/null @@ -1,49 +0,0 @@ -package app.embedded.com.aol.micro.server; - -import java.util.Arrays; -import java.util.List; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import cyclops.async.SimpleReact; -import cyclops.reactive.FutureStream; -import org.springframework.stereotype.Component; - - -import com.aol.micro.server.testing.RestAgent; -@Component -@Path("/test-status") -public class TestAppResource implements TestAppRestResource { - - private final SimpleReact simpleReact = new SimpleReact(); - private final RestAgent template = new RestAgent(); - private final List urls = Arrays.asList("http://localhost:8081/alternative-app/alt-status/ping", - "http://localhost:8080/test-app/test-status/ping", - "http://localhost:8082/simple-app/status/ping", - "http://localhost:8080/test-app/test-status/ping"); - - - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "test!"; - } - - @GET - @Produces("text/plain") - @Path("/rest-calls") - public String restCallResult(){ - - return FutureStream.builder().fromIterable(urls) - .map(it ->template.get(it)) - .then(it -> "*"+it) - .peek(loadedAndModified -> System.out.println(loadedAndModified)) - .block().stream().reduce("", (acc,next) -> acc+"-"+next); - - } - -} diff --git a/micro-grizzly-with-jersey/src/test/java/app/embedded/com/aol/micro/server/TestAppRestResource.java b/micro-grizzly-with-jersey/src/test/java/app/embedded/com/aol/micro/server/TestAppRestResource.java deleted file mode 100644 index 3133fd8cc..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/embedded/com/aol/micro/server/TestAppRestResource.java +++ /dev/null @@ -1,7 +0,0 @@ -package app.embedded.com.aol.micro.server; - -import com.aol.micro.server.auto.discovery.RestResource; - -public interface TestAppRestResource extends RestResource { - -} diff --git a/micro-grizzly-with-jersey/src/test/java/app/embedded/com/oath/micro/server/AltAppResource.java b/micro-grizzly-with-jersey/src/test/java/app/embedded/com/oath/micro/server/AltAppResource.java new file mode 100644 index 000000000..1835ababe --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/embedded/com/oath/micro/server/AltAppResource.java @@ -0,0 +1,22 @@ +package app.embedded.com.oath.micro.server; + +import java.util.List; + +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.stereotype.Component; + +@Component +@Path("/alt-status") +public class AltAppResource implements AltAppRestResource { + + @POST + @Produces("application/json") + @Path("/ping") + public List ping(ImmutableEntity entity) { + return entity.getList(); + } + +} diff --git a/micro-grizzly-with-jersey/src/test/java/app/embedded/com/oath/micro/server/AltAppRestResource.java b/micro-grizzly-with-jersey/src/test/java/app/embedded/com/oath/micro/server/AltAppRestResource.java new file mode 100644 index 000000000..7045a4f35 --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/embedded/com/oath/micro/server/AltAppRestResource.java @@ -0,0 +1,7 @@ +package app.embedded.com.oath.micro.server; + +import com.oath.micro.server.auto.discovery.RestResource; + +public interface AltAppRestResource extends RestResource { + +} diff --git a/micro-grizzly-with-jersey/src/test/java/app/embedded/com/oath/micro/server/EmbeddedAppLocalMain.java b/micro-grizzly-with-jersey/src/test/java/app/embedded/com/oath/micro/server/EmbeddedAppLocalMain.java new file mode 100644 index 000000000..dbb290069 --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/embedded/com/oath/micro/server/EmbeddedAppLocalMain.java @@ -0,0 +1,24 @@ +package app.embedded.com.oath.micro.server; + +import java.util.Arrays; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.module.EmbeddedModule; + +@Microserver(basePackages = { "app.embedded.com.oath.micro.server" }) +public class EmbeddedAppLocalMain { + + + public static void main(String[] args) throws InterruptedException { + + new MicroserverApp( + EmbeddedModule.tagInterfaceModule(Arrays.asList(TestAppRestResource.class),"test-app"), + EmbeddedModule.tagInterfaceModule(Arrays.asList(AltAppRestResource.class),"alternative-app")).start(); + + + + } + + +} diff --git a/micro-grizzly-with-jersey/src/test/java/app/embedded/com/oath/micro/server/EmbeddedAppTest.java b/micro-grizzly-with-jersey/src/test/java/app/embedded/com/oath/micro/server/EmbeddedAppTest.java new file mode 100644 index 000000000..83eb220c1 --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/embedded/com/oath/micro/server/EmbeddedAppTest.java @@ -0,0 +1,102 @@ +package app.embedded.com.oath.micro.server; + +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; + +import javax.ws.rs.NotFoundException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.springframework.util.concurrent.ListenableFuture; +import org.springframework.util.concurrent.ListenableFutureCallback; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.module.EmbeddedModule; +import com.oath.micro.server.testing.RestAgent; + +public class EmbeddedAppTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + + @Before + public void startServer(){ + server = new MicroserverApp(EmbeddedAppLocalMain.class, + EmbeddedModule.tagInterfaceModule(Arrays.asList(TestAppRestResource.class),"test-app"), + EmbeddedModule.tagInterfaceModule(Arrays.asList(AltAppRestResource.class),"alternative-app")); + server.start(); + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void confirmExpectedUrlsPresentTest() throws InterruptedException, ExecutionException{ + + assertThat(rest.get("http://localhost:8080/test-app/test-status/ping"),is("test!")); + + + assertThat((List)rest.post("http://localhost:8081/alternative-app/alt-status/ping",new ImmutableEntity("value",Arrays.asList("hello","world")),List.class), + hasItem("hello")); + + } + + + @Test + public void nonBlockingRestClientTest(){ + assertThat(rest.get("http://localhost:8080/test-app/test-status/rest-calls"),is("-*test!-*test!")); + } + + CompletableFuture toCompletableFuture( + final ListenableFuture listenableFuture + ) { + //create an instance of CompletableFuture + CompletableFuture completable = new CompletableFuture() { + @Override + public boolean cancel(boolean mayInterruptIfRunning) { + // propagate cancel to the listenable future + boolean result = listenableFuture.cancel(mayInterruptIfRunning); + super.cancel(mayInterruptIfRunning); + return result; + } + }; + + // add callback + listenableFuture.addCallback(new ListenableFutureCallback() { + @Override + public void onSuccess(T result) { + completable.complete(result); + } + + @Override + public void onFailure(Throwable t) { + completable.completeExceptionally(t); + } + }); + return completable; + } + + @Test(expected=NotFoundException.class) + public void confirmAltAppCantUseTestAppResources(){ + + assertThat(rest.get("http://localhost:8080/alternative-app/test-status/ping"),is("test!")); + + } + @Test(expected=NotFoundException.class) + public void confirmTestAppCantUseAltAppResources(){ + + assertThat((List)rest.post("http://localhost:8081/test-app/alt-status/ping",new ImmutableEntity("value",Arrays.asList("hello","world")),List.class), + hasItem("hello")); + + } +} diff --git a/micro-grizzly-with-jersey/src/test/java/app/embedded/com/oath/micro/server/ImmutableEntity.java b/micro-grizzly-with-jersey/src/test/java/app/embedded/com/oath/micro/server/ImmutableEntity.java new file mode 100644 index 000000000..337b63b89 --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/embedded/com/oath/micro/server/ImmutableEntity.java @@ -0,0 +1,29 @@ +package app.embedded.com.oath.micro.server; + +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Builder; + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "") +@XmlRootElement(name = "immutable") +@Getter +@AllArgsConstructor +@Builder +public class ImmutableEntity { + + private final String value; + private final List list; + + public ImmutableEntity() { + this(null,null); + } + +} diff --git a/micro-grizzly-with-jersey/src/test/java/app/embedded/com/oath/micro/server/TestAppResource.java b/micro-grizzly-with-jersey/src/test/java/app/embedded/com/oath/micro/server/TestAppResource.java new file mode 100644 index 000000000..ebf830d95 --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/embedded/com/oath/micro/server/TestAppResource.java @@ -0,0 +1,49 @@ +package app.embedded.com.oath.micro.server; + +import java.util.Arrays; +import java.util.List; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import cyclops.async.SimpleReact; +import cyclops.reactive.FutureStream; +import org.springframework.stereotype.Component; + + +import com.oath.micro.server.testing.RestAgent; +@Component +@Path("/test-status") +public class TestAppResource implements TestAppRestResource { + + private final SimpleReact simpleReact = new SimpleReact(); + private final RestAgent template = new RestAgent(); + private final List urls = Arrays.asList("http://localhost:8081/alternative-app/alt-status/ping", + "http://localhost:8080/test-app/test-status/ping", + "http://localhost:8082/simple-app/status/ping", + "http://localhost:8080/test-app/test-status/ping"); + + + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "test!"; + } + + @GET + @Produces("text/plain") + @Path("/rest-calls") + public String restCallResult(){ + + return FutureStream.builder().fromIterable(urls) + .map(it ->template.get(it)) + .then(it -> "*"+it) + .peek(loadedAndModified -> System.out.println(loadedAndModified)) + .block().stream().reduce("", (acc,next) -> acc+"-"+next); + + } + +} diff --git a/micro-grizzly-with-jersey/src/test/java/app/embedded/com/oath/micro/server/TestAppRestResource.java b/micro-grizzly-with-jersey/src/test/java/app/embedded/com/oath/micro/server/TestAppRestResource.java new file mode 100644 index 000000000..7d4df5753 --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/embedded/com/oath/micro/server/TestAppRestResource.java @@ -0,0 +1,7 @@ +package app.embedded.com.oath.micro.server; + +import com.oath.micro.server.auto.discovery.RestResource; + +public interface TestAppRestResource extends RestResource { + +} diff --git a/micro-grizzly-with-jersey/src/test/java/app/filter/com/aol/micro/server/AutodiscoveredFilter.java b/micro-grizzly-with-jersey/src/test/java/app/filter/com/aol/micro/server/AutodiscoveredFilter.java deleted file mode 100644 index 52a8959db..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/filter/com/aol/micro/server/AutodiscoveredFilter.java +++ /dev/null @@ -1,70 +0,0 @@ -package app.filter.com.aol.micro.server; - -import java.io.IOException; - -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; - -import cyclops.control.Either; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - - -import com.aol.micro.server.auto.discovery.AutoFilterConfiguration; - -import lombok.Getter; -import lombok.Setter; - -@Component -public class AutodiscoveredFilter implements AutoFilterConfiguration { - - @Autowired - Bean bean; - @Getter - @Setter - private static volatile int called= 0; - - @Getter - private static boolean beanSet = false; - - @Override - public String[] getMapping() { - return new String[] { "/*" }; - } - public Either,Filter> getFilter(){ - - return Either.left(org.springframework.web.filter.DelegatingFilterProxy.class); - - } - public String getName(){ - return "autodiscoveredFilter"; - } - - @Override - public void init(FilterConfig filterConfig) throws ServletException { - - } - - @Override - public void doFilter(ServletRequest request, ServletResponse response, - FilterChain chain) throws IOException, ServletException { - - called++; - if(bean!=null) - beanSet =true; - chain.doFilter(request, response); - } - - @Override - public void destroy() { - - - } - - - -} \ No newline at end of file diff --git a/micro-grizzly-with-jersey/src/test/java/app/filter/com/aol/micro/server/Bean.java b/micro-grizzly-with-jersey/src/test/java/app/filter/com/aol/micro/server/Bean.java deleted file mode 100644 index f95b44b05..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/filter/com/aol/micro/server/Bean.java +++ /dev/null @@ -1,8 +0,0 @@ -package app.filter.com.aol.micro.server; - -import org.springframework.stereotype.Component; - -@Component -public class Bean { - -} diff --git a/micro-grizzly-with-jersey/src/test/java/app/filter/com/aol/micro/server/ConfiguredFilter.java b/micro-grizzly-with-jersey/src/test/java/app/filter/com/aol/micro/server/ConfiguredFilter.java deleted file mode 100644 index e00bc941b..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/filter/com/aol/micro/server/ConfiguredFilter.java +++ /dev/null @@ -1,38 +0,0 @@ -package app.filter.com.aol.micro.server; - -import java.io.IOException; - -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; - -import lombok.Getter; - -public class ConfiguredFilter implements Filter { - - @Getter - private static volatile int called= 0; - @Override - public void init(FilterConfig filterConfig) throws ServletException { - // TODO Auto-generated method stub - - } - - @Override - public void doFilter(ServletRequest request, ServletResponse response, - FilterChain chain) throws IOException, ServletException { - called++; - chain.doFilter(request, response); - - } - - @Override - public void destroy() { - // TODO Auto-generated method stub - - } - -} diff --git a/micro-grizzly-with-jersey/src/test/java/app/filter/com/aol/micro/server/FilterAppLocalMain.java b/micro-grizzly-with-jersey/src/test/java/app/filter/com/aol/micro/server/FilterAppLocalMain.java deleted file mode 100644 index 25dc01cc3..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/filter/com/aol/micro/server/FilterAppLocalMain.java +++ /dev/null @@ -1,22 +0,0 @@ -package app.filter.com.aol.micro.server; - -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; - -import app.servlet.com.aol.micro.server.AppRunnerLocalMain; - -import com.aol.micro.server.MicroserverApp; -@Configuration -@ComponentScan(basePackages = { "app.filter.com.aol.micro.server" }) -public class FilterAppLocalMain { - - - - - public static void main(String[] args) throws InterruptedException { - - new MicroserverApp( FilterAppLocalMain.class, () -> "filter-app") - .run(); - } - - } \ No newline at end of file diff --git a/micro-grizzly-with-jersey/src/test/java/app/filter/com/aol/micro/server/FilterRunnerTest.java b/micro-grizzly-with-jersey/src/test/java/app/filter/com/aol/micro/server/FilterRunnerTest.java deleted file mode 100644 index 239ca7258..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/filter/com/aol/micro/server/FilterRunnerTest.java +++ /dev/null @@ -1,64 +0,0 @@ -package app.filter.com.aol.micro.server; - - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.Arrays; -import java.util.Map; -import java.util.concurrent.ExecutionException; - -import javax.servlet.Filter; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.testing.RestAgent; -import com.aol.micro.server.utility.HashMapBuilder; - - - -public class FilterRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer(){ - Map filters = HashMapBuilder.map("/filter-app/status/ping2",new ConfiguredFilter()).build(); - server = new MicroserverApp(ConfigurableModule.builder() - .context("filter-app") - .filters(filters ) - .requestListeners(Arrays.asList(new org.springframework.web.context.request.RequestContextListener())).build()); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void testAutoDiscoveredFilter() throws InterruptedException, ExecutionException{ - AutodiscoveredFilter.setCalled(0); - - assertThat(rest.get("http://localhost:8080/filter-app/status/ping"),is("ok")); - assertThat(AutodiscoveredFilter.getCalled(),is(1)); - assertThat(AutodiscoveredFilter.isBeanSet(),is(true)); - } - @Test - public void testConfiguredFilter() throws InterruptedException, ExecutionException{ - - assertThat(ConfiguredFilter.getCalled(),is(0)); - assertThat(rest.get("http://localhost:8080/filter-app/status/ping2"),is("ok")); - assertThat(ConfiguredFilter.getCalled(),is(1)); - } - - - - -} diff --git a/micro-grizzly-with-jersey/src/test/java/app/filter/com/aol/micro/server/FilterStatusResource.java b/micro-grizzly-with-jersey/src/test/java/app/filter/com/aol/micro/server/FilterStatusResource.java deleted file mode 100644 index 2d046711b..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/filter/com/aol/micro/server/FilterStatusResource.java +++ /dev/null @@ -1,37 +0,0 @@ -package app.filter.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.config.ConfigurableBeanFactory; -import org.springframework.context.annotation.Scope; -import org.springframework.stereotype.Component; -import org.springframework.web.context.WebApplicationContext; - -import com.aol.micro.server.auto.discovery.RestResource; - -@Component -@Scope(value=ConfigurableBeanFactory.SCOPE_PROTOTYPE) -@Path("/status") -public class FilterStatusResource implements RestResource { - - @Autowired - private RequestScopeUserInfo info; - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - info.print(); - return "ok"; - } - @GET - @Produces("text/plain") - @Path("/ping2") - public String ping2() { - return "ok"; - } - -} \ No newline at end of file diff --git a/micro-grizzly-with-jersey/src/test/java/app/filter/com/aol/micro/server/RequestScopeUserInfo.java b/micro-grizzly-with-jersey/src/test/java/app/filter/com/aol/micro/server/RequestScopeUserInfo.java deleted file mode 100644 index c41605c39..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/filter/com/aol/micro/server/RequestScopeUserInfo.java +++ /dev/null @@ -1,20 +0,0 @@ -package app.filter.com.aol.micro.server; - -import javax.servlet.http.HttpServletRequest; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Scope; -import org.springframework.context.annotation.ScopedProxyMode; -import org.springframework.stereotype.Component; -import org.springframework.web.context.WebApplicationContext; - -@Component -@Scope(value=WebApplicationContext.SCOPE_REQUEST,proxyMode=ScopedProxyMode.TARGET_CLASS) -public class RequestScopeUserInfo { - @Autowired - private HttpServletRequest request; - - public void print(){ - System.out.println(request.getAttribute("oc.info")); - } -} diff --git a/micro-grizzly-with-jersey/src/test/java/app/filter/com/oath/micro/server/AutodiscoveredFilter.java b/micro-grizzly-with-jersey/src/test/java/app/filter/com/oath/micro/server/AutodiscoveredFilter.java new file mode 100644 index 000000000..1f6dfc284 --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/filter/com/oath/micro/server/AutodiscoveredFilter.java @@ -0,0 +1,70 @@ +package app.filter.com.oath.micro.server; + +import java.io.IOException; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; + +import cyclops.control.Either; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + + +import com.oath.micro.server.auto.discovery.AutoFilterConfiguration; + +import lombok.Getter; +import lombok.Setter; + +@Component +public class AutodiscoveredFilter implements AutoFilterConfiguration { + + @Autowired + Bean bean; + @Getter + @Setter + private static volatile int called= 0; + + @Getter + private static boolean beanSet = false; + + @Override + public String[] getMapping() { + return new String[] { "/*" }; + } + public Either,Filter> getFilter(){ + + return Either.left(org.springframework.web.filter.DelegatingFilterProxy.class); + + } + public String getName(){ + return "autodiscoveredFilter"; + } + + @Override + public void init(FilterConfig filterConfig) throws ServletException { + + } + + @Override + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + called++; + if(bean!=null) + beanSet =true; + chain.doFilter(request, response); + } + + @Override + public void destroy() { + + + } + + + +} \ No newline at end of file diff --git a/micro-grizzly-with-jersey/src/test/java/app/filter/com/oath/micro/server/Bean.java b/micro-grizzly-with-jersey/src/test/java/app/filter/com/oath/micro/server/Bean.java new file mode 100644 index 000000000..e036a796f --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/filter/com/oath/micro/server/Bean.java @@ -0,0 +1,8 @@ +package app.filter.com.oath.micro.server; + +import org.springframework.stereotype.Component; + +@Component +public class Bean { + +} diff --git a/micro-grizzly-with-jersey/src/test/java/app/filter/com/oath/micro/server/ConfiguredFilter.java b/micro-grizzly-with-jersey/src/test/java/app/filter/com/oath/micro/server/ConfiguredFilter.java new file mode 100644 index 000000000..aca52ad38 --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/filter/com/oath/micro/server/ConfiguredFilter.java @@ -0,0 +1,38 @@ +package app.filter.com.oath.micro.server; + +import java.io.IOException; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; + +import lombok.Getter; + +public class ConfiguredFilter implements Filter { + + @Getter + private static volatile int called= 0; + @Override + public void init(FilterConfig filterConfig) throws ServletException { + // TODO Auto-generated method stub + + } + + @Override + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + called++; + chain.doFilter(request, response); + + } + + @Override + public void destroy() { + // TODO Auto-generated method stub + + } + +} diff --git a/micro-grizzly-with-jersey/src/test/java/app/filter/com/oath/micro/server/FilterAppLocalMain.java b/micro-grizzly-with-jersey/src/test/java/app/filter/com/oath/micro/server/FilterAppLocalMain.java new file mode 100644 index 000000000..b650780a2 --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/filter/com/oath/micro/server/FilterAppLocalMain.java @@ -0,0 +1,20 @@ +package app.filter.com.oath.micro.server; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +import com.oath.micro.server.MicroserverApp; +@Configuration +@ComponentScan(basePackages = { "app.filter.com.aol.micro.server" }) +public class FilterAppLocalMain { + + + + + public static void main(String[] args) throws InterruptedException { + + new MicroserverApp( FilterAppLocalMain.class, () -> "filter-app") + .run(); + } + + } \ No newline at end of file diff --git a/micro-grizzly-with-jersey/src/test/java/app/filter/com/oath/micro/server/FilterRunnerTest.java b/micro-grizzly-with-jersey/src/test/java/app/filter/com/oath/micro/server/FilterRunnerTest.java new file mode 100644 index 000000000..d3c136b4a --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/filter/com/oath/micro/server/FilterRunnerTest.java @@ -0,0 +1,64 @@ +package app.filter.com.oath.micro.server; + + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.Arrays; +import java.util.Map; +import java.util.concurrent.ExecutionException; + +import javax.servlet.Filter; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.module.ConfigurableModule; +import com.oath.micro.server.testing.RestAgent; +import com.oath.micro.server.utility.HashMapBuilder; + + + +public class FilterRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer(){ + Map filters = HashMapBuilder.map("/filter-app/status/ping2",new ConfiguredFilter()).build(); + server = new MicroserverApp(ConfigurableModule.builder() + .context("filter-app") + .filters(filters ) + .requestListeners(Arrays.asList(new org.springframework.web.context.request.RequestContextListener())).build()); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void testAutoDiscoveredFilter() throws InterruptedException, ExecutionException{ + AutodiscoveredFilter.setCalled(0); + + assertThat(rest.get("http://localhost:8080/filter-app/status/ping"),is("ok")); + assertThat(AutodiscoveredFilter.getCalled(),is(1)); + assertThat(AutodiscoveredFilter.isBeanSet(),is(true)); + } + @Test + public void testConfiguredFilter() throws InterruptedException, ExecutionException{ + + assertThat(ConfiguredFilter.getCalled(),is(0)); + assertThat(rest.get("http://localhost:8080/filter-app/status/ping2"),is("ok")); + assertThat(ConfiguredFilter.getCalled(),is(1)); + } + + + + +} diff --git a/micro-grizzly-with-jersey/src/test/java/app/filter/com/oath/micro/server/FilterStatusResource.java b/micro-grizzly-with-jersey/src/test/java/app/filter/com/oath/micro/server/FilterStatusResource.java new file mode 100644 index 000000000..c7166c216 --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/filter/com/oath/micro/server/FilterStatusResource.java @@ -0,0 +1,36 @@ +package app.filter.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.RestResource; + +@Component +@Scope(value=ConfigurableBeanFactory.SCOPE_PROTOTYPE) +@Path("/status") +public class FilterStatusResource implements RestResource { + + @Autowired + private RequestScopeUserInfo info; + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + info.print(); + return "ok"; + } + @GET + @Produces("text/plain") + @Path("/ping2") + public String ping2() { + return "ok"; + } + +} \ No newline at end of file diff --git a/micro-grizzly-with-jersey/src/test/java/app/filter/com/oath/micro/server/RequestScopeUserInfo.java b/micro-grizzly-with-jersey/src/test/java/app/filter/com/oath/micro/server/RequestScopeUserInfo.java new file mode 100644 index 000000000..84c19c3f4 --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/filter/com/oath/micro/server/RequestScopeUserInfo.java @@ -0,0 +1,20 @@ +package app.filter.com.oath.micro.server; + +import javax.servlet.http.HttpServletRequest; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Scope; +import org.springframework.context.annotation.ScopedProxyMode; +import org.springframework.stereotype.Component; +import org.springframework.web.context.WebApplicationContext; + +@Component +@Scope(value=WebApplicationContext.SCOPE_REQUEST,proxyMode=ScopedProxyMode.TARGET_CLASS) +public class RequestScopeUserInfo { + @Autowired + private HttpServletRequest request; + + public void print(){ + System.out.println(request.getAttribute("oc.info")); + } +} diff --git a/micro-grizzly-with-jersey/src/test/java/app/listeners/com/aol/micro/server/AutodiscoveredListener.java b/micro-grizzly-with-jersey/src/test/java/app/listeners/com/aol/micro/server/AutodiscoveredListener.java deleted file mode 100644 index bff7cbdc8..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/listeners/com/aol/micro/server/AutodiscoveredListener.java +++ /dev/null @@ -1,35 +0,0 @@ -package app.listeners.com.aol.micro.server; - -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; - -import lombok.Getter; - -import org.springframework.stereotype.Component; - -@Component -public class AutodiscoveredListener implements ServletContextListener { - - @Getter - private static volatile int called= 0; - - @Override - public void contextInitialized(ServletContextEvent sce) { - called ++; - - } - - @Override - public void contextDestroyed(ServletContextEvent sce) { - - - } - - - - - - - - -} \ No newline at end of file diff --git a/micro-grizzly-with-jersey/src/test/java/app/listeners/com/aol/micro/server/ConfiguredListener.java b/micro-grizzly-with-jersey/src/test/java/app/listeners/com/aol/micro/server/ConfiguredListener.java deleted file mode 100644 index d15dcb76e..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/listeners/com/aol/micro/server/ConfiguredListener.java +++ /dev/null @@ -1,25 +0,0 @@ -package app.listeners.com.aol.micro.server; - -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; - -import lombok.Getter; - -public class ConfiguredListener implements ServletContextListener { - - @Getter - private static volatile int called= 0; - - @Override - public void contextInitialized(ServletContextEvent sce) { - called ++; - - } - - @Override - public void contextDestroyed(ServletContextEvent sce) { - - - } - -} \ No newline at end of file diff --git a/micro-grizzly-with-jersey/src/test/java/app/listeners/com/aol/micro/server/ListenerRunnerTest.java b/micro-grizzly-with-jersey/src/test/java/app/listeners/com/aol/micro/server/ListenerRunnerTest.java deleted file mode 100644 index 4f8d7ab69..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/listeners/com/aol/micro/server/ListenerRunnerTest.java +++ /dev/null @@ -1,55 +0,0 @@ -package app.listeners.com.aol.micro.server; - - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.ExecutionException; - -import javax.servlet.ServletContextListener; - - - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.testing.RestAgent; - - -@Microserver -public class ListenerRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer(){ - List listeners = Arrays.asList(new ConfiguredListener()); - server = new MicroserverApp( ListenerRunnerTest.class, ConfigurableModule.builder().context("listener-app").listeners(listeners ).build()); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void testListeners() throws InterruptedException, ExecutionException{ - - assertThat(AutodiscoveredListener.getCalled(),is(1)); - assertThat(ConfiguredListener.getCalled(),is(1)); - } - - - - - -} diff --git a/micro-grizzly-with-jersey/src/test/java/app/listeners/com/oath/micro/server/AutodiscoveredListener.java b/micro-grizzly-with-jersey/src/test/java/app/listeners/com/oath/micro/server/AutodiscoveredListener.java new file mode 100644 index 000000000..a3dfdff21 --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/listeners/com/oath/micro/server/AutodiscoveredListener.java @@ -0,0 +1,35 @@ +package app.listeners.com.oath.micro.server; + +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; + +import lombok.Getter; + +import org.springframework.stereotype.Component; + +@Component +public class AutodiscoveredListener implements ServletContextListener { + + @Getter + private static volatile int called= 0; + + @Override + public void contextInitialized(ServletContextEvent sce) { + called ++; + + } + + @Override + public void contextDestroyed(ServletContextEvent sce) { + + + } + + + + + + + + +} \ No newline at end of file diff --git a/micro-grizzly-with-jersey/src/test/java/app/listeners/com/oath/micro/server/ConfiguredListener.java b/micro-grizzly-with-jersey/src/test/java/app/listeners/com/oath/micro/server/ConfiguredListener.java new file mode 100644 index 000000000..86a7cd34b --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/listeners/com/oath/micro/server/ConfiguredListener.java @@ -0,0 +1,25 @@ +package app.listeners.com.oath.micro.server; + +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; + +import lombok.Getter; + +public class ConfiguredListener implements ServletContextListener { + + @Getter + private static volatile int called= 0; + + @Override + public void contextInitialized(ServletContextEvent sce) { + called ++; + + } + + @Override + public void contextDestroyed(ServletContextEvent sce) { + + + } + +} \ No newline at end of file diff --git a/micro-grizzly-with-jersey/src/test/java/app/listeners/com/oath/micro/server/ListenerRunnerTest.java b/micro-grizzly-with-jersey/src/test/java/app/listeners/com/oath/micro/server/ListenerRunnerTest.java new file mode 100644 index 000000000..fa0222a76 --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/listeners/com/oath/micro/server/ListenerRunnerTest.java @@ -0,0 +1,55 @@ +package app.listeners.com.oath.micro.server; + + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.ExecutionException; + +import javax.servlet.ServletContextListener; + + + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.module.ConfigurableModule; +import com.oath.micro.server.testing.RestAgent; + + +@Microserver +public class ListenerRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer(){ + List listeners = Arrays.asList(new ConfiguredListener()); + server = new MicroserverApp( ListenerRunnerTest.class, ConfigurableModule.builder().context("listener-app").listeners(listeners ).build()); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void testListeners() throws InterruptedException, ExecutionException{ + + assertThat(AutodiscoveredListener.getCalled(),is(1)); + assertThat(ConfiguredListener.getCalled(),is(1)); + } + + + + + +} diff --git a/micro-grizzly-with-jersey/src/test/java/app/micro/server/servers/AccessLogConfigTest.java b/micro-grizzly-with-jersey/src/test/java/app/micro/server/servers/AccessLogConfigTest.java index 194988553..6611cabee 100644 --- a/micro-grizzly-with-jersey/src/test/java/app/micro/server/servers/AccessLogConfigTest.java +++ b/micro-grizzly-with-jersey/src/test/java/app/micro/server/servers/AccessLogConfigTest.java @@ -9,8 +9,8 @@ import org.junit.Before; import org.junit.Test; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; @Microserver(properties={"access.log.output", "${user.home}"}) public class AccessLogConfigTest { diff --git a/micro-grizzly-with-jersey/src/test/java/app/minimal/com/aol/micro/server/MinimalClassTest.java b/micro-grizzly-with-jersey/src/test/java/app/minimal/com/aol/micro/server/MinimalClassTest.java deleted file mode 100644 index 04367ecbd..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/minimal/com/aol/micro/server/MinimalClassTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package app.minimal.com.aol.micro.server; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.auto.discovery.RestResource; -import com.aol.micro.server.testing.RestAgent; - -@Rest -@Path("/single") -public class MinimalClassTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer(){ - - server = new MicroserverApp(()-> "minimal-app"); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - - - assertThat(rest.get("http://localhost:8080/minimal-app/single/ping"),is("ok")); - - } - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "ok"; - } - - -} \ No newline at end of file diff --git a/micro-grizzly-with-jersey/src/test/java/app/minimal/com/oath/micro/server/MinimalClassTest.java b/micro-grizzly-with-jersey/src/test/java/app/minimal/com/oath/micro/server/MinimalClassTest.java new file mode 100644 index 000000000..c018eb7b2 --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/minimal/com/oath/micro/server/MinimalClassTest.java @@ -0,0 +1,57 @@ +package app.minimal.com.oath.micro.server; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.auto.discovery.Rest; +import com.oath.micro.server.testing.RestAgent; + +@Rest +@Path("/single") +public class MinimalClassTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer(){ + + server = new MicroserverApp(()-> "minimal-app"); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + + + assertThat(rest.get("http://localhost:8080/minimal-app/single/ping"),is("ok")); + + } + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "ok"; + } + + +} \ No newline at end of file diff --git a/micro-grizzly-with-jersey/src/test/java/app/noanno/com/aol/micro/server/copy/NoAnnoRunnerTest.java b/micro-grizzly-with-jersey/src/test/java/app/noanno/com/aol/micro/server/copy/NoAnnoRunnerTest.java deleted file mode 100644 index bb052650c..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/noanno/com/aol/micro/server/copy/NoAnnoRunnerTest.java +++ /dev/null @@ -1,48 +0,0 @@ -package app.noanno.com.aol.micro.server.copy; - - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.testing.RestAgent; - - -public class NoAnnoRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer(){ - - server = new MicroserverApp(()-> "simple-app"); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - - - assertThat(rest.get("http://localhost:8080/simple-app/status/ping"),is("ok")); - - - } - - - -} diff --git a/micro-grizzly-with-jersey/src/test/java/app/noanno/com/aol/micro/server/copy/NoAnnoStatusResource.java b/micro-grizzly-with-jersey/src/test/java/app/noanno/com/aol/micro/server/copy/NoAnnoStatusResource.java deleted file mode 100644 index 8a3f5efaa..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/noanno/com/aol/micro/server/copy/NoAnnoStatusResource.java +++ /dev/null @@ -1,24 +0,0 @@ -package app.noanno.com.aol.micro.server.copy; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import com.aol.micro.server.auto.discovery.Rest; - -@Rest -@Path("/status") -public class NoAnnoStatusResource { - - - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - - return "ok"; - } - - -} \ No newline at end of file diff --git a/micro-grizzly-with-jersey/src/test/java/app/noanno/com/aol/micro/server/copy/SimpleApp.java b/micro-grizzly-with-jersey/src/test/java/app/noanno/com/aol/micro/server/copy/SimpleApp.java deleted file mode 100644 index 5fb7e2ca3..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/noanno/com/aol/micro/server/copy/SimpleApp.java +++ /dev/null @@ -1,12 +0,0 @@ -package app.noanno.com.aol.micro.server.copy; - -import com.aol.micro.server.MicroserverApp; - -public class SimpleApp { - - public static void main(String[] args){ - new MicroserverApp(()-> "simple-app").run(); - } - - -} diff --git a/micro-grizzly-with-jersey/src/test/java/app/noanno/com/oath/micro/server/copy/NoAnnoRunnerTest.java b/micro-grizzly-with-jersey/src/test/java/app/noanno/com/oath/micro/server/copy/NoAnnoRunnerTest.java new file mode 100644 index 000000000..589bf5144 --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/noanno/com/oath/micro/server/copy/NoAnnoRunnerTest.java @@ -0,0 +1,47 @@ +package app.noanno.com.oath.micro.server.copy; + + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.testing.RestAgent; + + +public class NoAnnoRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer(){ + + server = new MicroserverApp(()-> "simple-app"); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + + + assertThat(rest.get("http://localhost:8080/simple-app/status/ping"),is("ok")); + + + } + + + +} diff --git a/micro-grizzly-with-jersey/src/test/java/app/noanno/com/oath/micro/server/copy/NoAnnoStatusResource.java b/micro-grizzly-with-jersey/src/test/java/app/noanno/com/oath/micro/server/copy/NoAnnoStatusResource.java new file mode 100644 index 000000000..11a42968e --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/noanno/com/oath/micro/server/copy/NoAnnoStatusResource.java @@ -0,0 +1,24 @@ +package app.noanno.com.oath.micro.server.copy; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import com.oath.micro.server.auto.discovery.Rest; + +@Rest +@Path("/status") +public class NoAnnoStatusResource { + + + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + + return "ok"; + } + + +} \ No newline at end of file diff --git a/micro-grizzly-with-jersey/src/test/java/app/noanno/com/oath/micro/server/copy/SimpleApp.java b/micro-grizzly-with-jersey/src/test/java/app/noanno/com/oath/micro/server/copy/SimpleApp.java new file mode 100644 index 000000000..646004a31 --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/noanno/com/oath/micro/server/copy/SimpleApp.java @@ -0,0 +1,12 @@ +package app.noanno.com.oath.micro.server.copy; + +import com.oath.micro.server.MicroserverApp; + +public class SimpleApp { + + public static void main(String[] args){ + new MicroserverApp(()-> "simple-app").run(); + } + + +} diff --git a/micro-grizzly-with-jersey/src/test/java/app/properties/instance/com/aol/micro/server/ServicePropertiesTest.java b/micro-grizzly-with-jersey/src/test/java/app/properties/instance/com/aol/micro/server/ServicePropertiesTest.java deleted file mode 100644 index 0b12749f9..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/properties/instance/com/aol/micro/server/ServicePropertiesTest.java +++ /dev/null @@ -1,65 +0,0 @@ -package app.properties.instance.com.aol.micro.server; - -import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.springframework.beans.factory.annotation.Value; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.testing.RestAgent; - -@Rest -@Path("/single") -@Microserver(instancePropertiesName="myinstance.properties") -public class ServicePropertiesTest { - - RestAgent rest = new RestAgent(); - - @Value("${type.property}") - private String type; - MicroserverApp server; - @Before - public void startServer(){ - - server = new MicroserverApp(()-> "minimal-app"); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - - - assertThat(rest.get("http://localhost:8080/minimal-app/single/ping"),is("ok")); - - - - } - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - assertThat(type,equalTo("instance")); - return "ok"; - } - - -} \ No newline at end of file diff --git a/micro-grizzly-with-jersey/src/test/java/app/properties/instance/com/oath/micro/server/ServicePropertiesTest.java b/micro-grizzly-with-jersey/src/test/java/app/properties/instance/com/oath/micro/server/ServicePropertiesTest.java new file mode 100644 index 000000000..7ef55708f --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/properties/instance/com/oath/micro/server/ServicePropertiesTest.java @@ -0,0 +1,65 @@ +package app.properties.instance.com.oath.micro.server; + +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Value; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.auto.discovery.Rest; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.testing.RestAgent; + +@Rest +@Path("/single") +@Microserver(instancePropertiesName="myinstance.properties") +public class ServicePropertiesTest { + + RestAgent rest = new RestAgent(); + + @Value("${type.property}") + private String type; + MicroserverApp server; + @Before + public void startServer(){ + + server = new MicroserverApp(()-> "minimal-app"); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + + + assertThat(rest.get("http://localhost:8080/minimal-app/single/ping"),is("ok")); + + + + } + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + assertThat(type,equalTo("instance")); + return "ok"; + } + + +} \ No newline at end of file diff --git a/micro-grizzly-with-jersey/src/test/java/app/properties/service/com/aol/micro/server/ServicePropertiesTest.java b/micro-grizzly-with-jersey/src/test/java/app/properties/service/com/aol/micro/server/ServicePropertiesTest.java deleted file mode 100644 index 84ceba8d7..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/properties/service/com/aol/micro/server/ServicePropertiesTest.java +++ /dev/null @@ -1,65 +0,0 @@ -package app.properties.service.com.aol.micro.server; - -import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.springframework.beans.factory.annotation.Value; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.testing.RestAgent; - -@Rest -@Path("/single") -@Microserver(serviceTypePropertiesName="myservice.properties") -public class ServicePropertiesTest { - - RestAgent rest = new RestAgent(); - - @Value("${type.property}") - private String type; - MicroserverApp server; - @Before - public void startServer(){ - - server = new MicroserverApp(()-> "minimal-app"); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - - - assertThat(rest.get("http://localhost:8080/minimal-app/single/ping"),is("ok")); - - - - } - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - assertThat(type,equalTo("set")); - return "ok"; - } - - -} \ No newline at end of file diff --git a/micro-grizzly-with-jersey/src/test/java/app/properties/service/com/oath/micro/server/ServicePropertiesTest.java b/micro-grizzly-with-jersey/src/test/java/app/properties/service/com/oath/micro/server/ServicePropertiesTest.java new file mode 100644 index 000000000..d260cb148 --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/properties/service/com/oath/micro/server/ServicePropertiesTest.java @@ -0,0 +1,65 @@ +package app.properties.service.com.oath.micro.server; + +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Value; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.auto.discovery.Rest; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.testing.RestAgent; + +@Rest +@Path("/single") +@Microserver(serviceTypePropertiesName="myservice.properties") +public class ServicePropertiesTest { + + RestAgent rest = new RestAgent(); + + @Value("${type.property}") + private String type; + MicroserverApp server; + @Before + public void startServer(){ + + server = new MicroserverApp(()-> "minimal-app"); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + + + assertThat(rest.get("http://localhost:8080/minimal-app/single/ping"),is("ok")); + + + + } + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + assertThat(type,equalTo("set")); + return "ok"; + } + + +} \ No newline at end of file diff --git a/micro-grizzly-with-jersey/src/test/java/app/publisher/binder/direct/AsyncPublisherTest.java b/micro-grizzly-with-jersey/src/test/java/app/publisher/binder/direct/AsyncPublisherTest.java index a17cb514e..980efe728 100644 --- a/micro-grizzly-with-jersey/src/test/java/app/publisher/binder/direct/AsyncPublisherTest.java +++ b/micro-grizzly-with-jersey/src/test/java/app/publisher/binder/direct/AsyncPublisherTest.java @@ -1,11 +1,8 @@ package app.publisher.binder.direct; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.rest.jersey.AsyncBinder; -import com.aol.micro.server.testing.RestAgent; -import org.glassfish.jersey.server.ResourceConfig; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.testing.RestAgent; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/micro-grizzly-with-jersey/src/test/java/app/publisher/binder/direct/AsyncResource.java b/micro-grizzly-with-jersey/src/test/java/app/publisher/binder/direct/AsyncResource.java index f73a6e1fc..b9ab19e82 100644 --- a/micro-grizzly-with-jersey/src/test/java/app/publisher/binder/direct/AsyncResource.java +++ b/micro-grizzly-with-jersey/src/test/java/app/publisher/binder/direct/AsyncResource.java @@ -1,6 +1,6 @@ package app.publisher.binder.direct; -import com.aol.micro.server.auto.discovery.Rest; +import com.oath.micro.server.auto.discovery.Rest; import cyclops.async.Future; import cyclops.reactive.ReactiveSeq; import cyclops.reactive.Spouts; diff --git a/micro-grizzly-with-jersey/src/test/java/app/servlet/com/aol/micro/server/AppRunnerLocalMain.java b/micro-grizzly-with-jersey/src/test/java/app/servlet/com/aol/micro/server/AppRunnerLocalMain.java deleted file mode 100644 index b447491a1..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/servlet/com/aol/micro/server/AppRunnerLocalMain.java +++ /dev/null @@ -1,20 +0,0 @@ -package app.servlet.com.aol.micro.server; - - -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; - -import com.aol.micro.server.MicroserverApp; - -@Configuration -@ComponentScan(basePackages = { "app.servlet.com.aol.micro.server" }) -public class AppRunnerLocalMain { - - - public static void main(String[] args) throws InterruptedException { - - new MicroserverApp( AppRunnerLocalMain.class, () -> "test-app") - .run(); - } - -} diff --git a/micro-grizzly-with-jersey/src/test/java/app/servlet/com/aol/micro/server/AutodiscoveredServlet.java b/micro-grizzly-with-jersey/src/test/java/app/servlet/com/aol/micro/server/AutodiscoveredServlet.java deleted file mode 100644 index 3e64043bf..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/servlet/com/aol/micro/server/AutodiscoveredServlet.java +++ /dev/null @@ -1,30 +0,0 @@ -package app.servlet.com.aol.micro.server; - -import java.io.IOException; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.AutoServletConfiguration; - -@Component -public class AutodiscoveredServlet extends HttpServlet implements AutoServletConfiguration { - - @Override - public String[] getMapping() { - return new String[] { "/servlet" }; - } - - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) - throws ServletException, IOException { - - resp.setContentType("text/html"); - resp.getWriter().write("hello world"); - } - -} diff --git a/micro-grizzly-with-jersey/src/test/java/app/servlet/com/aol/micro/server/ConfiguredServlet.java b/micro-grizzly-with-jersey/src/test/java/app/servlet/com/aol/micro/server/ConfiguredServlet.java deleted file mode 100644 index 92577a92e..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/servlet/com/aol/micro/server/ConfiguredServlet.java +++ /dev/null @@ -1,24 +0,0 @@ -package app.servlet.com.aol.micro.server; - -import java.io.IOException; - -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -public class ConfiguredServlet extends HttpServlet { - - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) - throws ServletException, IOException { - resp.setContentType("text/html"); - resp.getWriter().write("configured servlet"); - } - - - -} diff --git a/micro-grizzly-with-jersey/src/test/java/app/servlet/com/aol/micro/server/ServletRunnerTest.java b/micro-grizzly-with-jersey/src/test/java/app/servlet/com/aol/micro/server/ServletRunnerTest.java deleted file mode 100644 index aa6e20b4f..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/servlet/com/aol/micro/server/ServletRunnerTest.java +++ /dev/null @@ -1,64 +0,0 @@ -package app.servlet.com.aol.micro.server; - - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.ExecutionException; - -import javax.servlet.Servlet; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.testing.RestAgent; - -public class ServletRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer(){ - Map servlets = new HashMap<>(); - servlets.put("/configured", new ConfiguredServlet()); - server = new MicroserverApp( AppRunnerLocalMain.class, ConfigurableModule.builder().context("test-app").servlets(servlets ).build()); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - assertThat(rest.get("http://localhost:8080/test-app/servlet/ping"),is("ok")); - - } - - @Test - public void autoDiscoveredServletTest() throws InterruptedException, ExecutionException{ - - - assertThat(rest.get("http://localhost:8080/servlet"),is("hello world")); - - } - - @Test - public void configuredServletTest() throws InterruptedException, ExecutionException{ - - - assertThat(rest.get("http://localhost:8080/configured"),is("configured servlet")); - - } - - -} diff --git a/micro-grizzly-with-jersey/src/test/java/app/servlet/com/aol/micro/server/ServletStatusResource.java b/micro-grizzly-with-jersey/src/test/java/app/servlet/com/aol/micro/server/ServletStatusResource.java deleted file mode 100644 index 890a64679..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/servlet/com/aol/micro/server/ServletStatusResource.java +++ /dev/null @@ -1,22 +0,0 @@ -package app.servlet.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.RestResource; - -@Component -@Path("/servlet") -public class ServletStatusResource implements RestResource { - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "ok"; - } - -} \ No newline at end of file diff --git a/micro-grizzly-with-jersey/src/test/java/app/servlet/com/oath/micro/server/AppRunnerLocalMain.java b/micro-grizzly-with-jersey/src/test/java/app/servlet/com/oath/micro/server/AppRunnerLocalMain.java new file mode 100644 index 000000000..065973f62 --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/servlet/com/oath/micro/server/AppRunnerLocalMain.java @@ -0,0 +1,20 @@ +package app.servlet.com.oath.micro.server; + + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +import com.oath.micro.server.MicroserverApp; + +@Configuration +@ComponentScan(basePackages = { "app.servlet.com.aol.micro.server" }) +public class AppRunnerLocalMain { + + + public static void main(String[] args) throws InterruptedException { + + new MicroserverApp( AppRunnerLocalMain.class, () -> "test-app") + .run(); + } + +} diff --git a/micro-grizzly-with-jersey/src/test/java/app/servlet/com/oath/micro/server/AutodiscoveredServlet.java b/micro-grizzly-with-jersey/src/test/java/app/servlet/com/oath/micro/server/AutodiscoveredServlet.java new file mode 100644 index 000000000..66cbfd59c --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/servlet/com/oath/micro/server/AutodiscoveredServlet.java @@ -0,0 +1,30 @@ +package app.servlet.com.oath.micro.server; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.AutoServletConfiguration; + +@Component +public class AutodiscoveredServlet extends HttpServlet implements AutoServletConfiguration { + + @Override + public String[] getMapping() { + return new String[] { "/servlet" }; + } + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + + resp.setContentType("text/html"); + resp.getWriter().write("hello world"); + } + +} diff --git a/micro-grizzly-with-jersey/src/test/java/app/servlet/com/oath/micro/server/ConfiguredServlet.java b/micro-grizzly-with-jersey/src/test/java/app/servlet/com/oath/micro/server/ConfiguredServlet.java new file mode 100644 index 000000000..65de82291 --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/servlet/com/oath/micro/server/ConfiguredServlet.java @@ -0,0 +1,21 @@ +package app.servlet.com.oath.micro.server; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class ConfiguredServlet extends HttpServlet { + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + resp.setContentType("text/html"); + resp.getWriter().write("configured servlet"); + } + + + +} diff --git a/micro-grizzly-with-jersey/src/test/java/app/servlet/com/oath/micro/server/ServletRunnerTest.java b/micro-grizzly-with-jersey/src/test/java/app/servlet/com/oath/micro/server/ServletRunnerTest.java new file mode 100644 index 000000000..39f3896e3 --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/servlet/com/oath/micro/server/ServletRunnerTest.java @@ -0,0 +1,64 @@ +package app.servlet.com.oath.micro.server; + + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ExecutionException; + +import javax.servlet.Servlet; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.module.ConfigurableModule; +import com.oath.micro.server.testing.RestAgent; + +public class ServletRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer(){ + Map servlets = new HashMap<>(); + servlets.put("/configured", new ConfiguredServlet()); + server = new MicroserverApp( AppRunnerLocalMain.class, ConfigurableModule.builder().context("test-app").servlets(servlets ).build()); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + assertThat(rest.get("http://localhost:8080/test-app/servlet/ping"),is("ok")); + + } + + @Test + public void autoDiscoveredServletTest() throws InterruptedException, ExecutionException{ + + + assertThat(rest.get("http://localhost:8080/servlet"),is("hello world")); + + } + + @Test + public void configuredServletTest() throws InterruptedException, ExecutionException{ + + + assertThat(rest.get("http://localhost:8080/configured"),is("configured servlet")); + + } + + +} diff --git a/micro-grizzly-with-jersey/src/test/java/app/servlet/com/oath/micro/server/ServletStatusResource.java b/micro-grizzly-with-jersey/src/test/java/app/servlet/com/oath/micro/server/ServletStatusResource.java new file mode 100644 index 000000000..6d86eeb84 --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/servlet/com/oath/micro/server/ServletStatusResource.java @@ -0,0 +1,22 @@ +package app.servlet.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.RestResource; + +@Component +@Path("/servlet") +public class ServletStatusResource implements RestResource { + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "ok"; + } + +} \ No newline at end of file diff --git a/micro-grizzly-with-jersey/src/test/java/app/simple/com/aol/micro/server/SimpleApp.java b/micro-grizzly-with-jersey/src/test/java/app/simple/com/aol/micro/server/SimpleApp.java deleted file mode 100644 index 700a2c778..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/simple/com/aol/micro/server/SimpleApp.java +++ /dev/null @@ -1,18 +0,0 @@ -package app.simple.com.aol.micro.server; - -import java.util.Arrays; - -import org.glassfish.jersey.media.multipart.MultiPartFeature; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.module.ConfigurableModule; - -public class SimpleApp { - - public static void main(String[] args){ - - new MicroserverApp(()-> "simple-app").run(); - } - - -} diff --git a/micro-grizzly-with-jersey/src/test/java/app/simple/com/aol/micro/server/SimpleRunnerTest.java b/micro-grizzly-with-jersey/src/test/java/app/simple/com/aol/micro/server/SimpleRunnerTest.java deleted file mode 100644 index 6249ef506..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/simple/com/aol/micro/server/SimpleRunnerTest.java +++ /dev/null @@ -1,55 +0,0 @@ -package app.simple.com.aol.micro.server; - - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.Arrays; -import java.util.concurrent.ExecutionException; - -import org.glassfish.jersey.media.multipart.MultiPartFeature; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.testing.RestAgent; - -@Microserver -public class SimpleRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer(){ - server = new MicroserverApp(ConfigurableModule - .builder() - .context("simple-app") - .defaultResources(Arrays.asList(MultiPartFeature.class)) - .build()); - // server = new MicroserverApp(()-> "simple-app"); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - - - assertThat(rest.get("http://localhost:8080/simple-app/status/ping"),is("ok")); - - - } - - - -} diff --git a/micro-grizzly-with-jersey/src/test/java/app/simple/com/aol/micro/server/SimpleStatusResource.java b/micro-grizzly-with-jersey/src/test/java/app/simple/com/aol/micro/server/SimpleStatusResource.java deleted file mode 100644 index 17e6c3e45..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/simple/com/aol/micro/server/SimpleStatusResource.java +++ /dev/null @@ -1,39 +0,0 @@ -package app.simple.com.aol.micro.server; - -import java.io.InputStream; - -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; - -import org.glassfish.jersey.media.multipart.FormDataContentDisposition; -import org.glassfish.jersey.media.multipart.FormDataParam; - -import com.aol.micro.server.auto.discovery.Rest; - -@Rest -@Path("/status") -public class SimpleStatusResource { - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - - return "ok"; - } - - @POST - @Consumes(MediaType.MULTIPART_FORM_DATA) - @Produces(MediaType.TEXT_PLAIN) - @Path("/file") - public String create( - @FormDataParam("file") InputStream fileInputStream, - @FormDataParam("file") FormDataContentDisposition contentDispositionHeader) { - - return "done"; - } -} \ No newline at end of file diff --git a/micro-grizzly-with-jersey/src/test/java/app/simple/com/oath/micro/server/SimpleApp.java b/micro-grizzly-with-jersey/src/test/java/app/simple/com/oath/micro/server/SimpleApp.java new file mode 100644 index 000000000..e82a92291 --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/simple/com/oath/micro/server/SimpleApp.java @@ -0,0 +1,13 @@ +package app.simple.com.oath.micro.server; + +import com.oath.micro.server.MicroserverApp; + +public class SimpleApp { + + public static void main(String[] args){ + + new MicroserverApp(()-> "simple-app").run(); + } + + +} diff --git a/micro-grizzly-with-jersey/src/test/java/app/simple/com/oath/micro/server/SimpleRunnerTest.java b/micro-grizzly-with-jersey/src/test/java/app/simple/com/oath/micro/server/SimpleRunnerTest.java new file mode 100644 index 000000000..ce6dd819a --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/simple/com/oath/micro/server/SimpleRunnerTest.java @@ -0,0 +1,55 @@ +package app.simple.com.oath.micro.server; + + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.Arrays; +import java.util.concurrent.ExecutionException; + +import org.glassfish.jersey.media.multipart.MultiPartFeature; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.module.ConfigurableModule; +import com.oath.micro.server.testing.RestAgent; + +@Microserver +public class SimpleRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer(){ + server = new MicroserverApp(ConfigurableModule + .builder() + .context("simple-app") + .defaultResources(Arrays.asList(MultiPartFeature.class)) + .build()); + // server = new MicroserverApp(()-> "simple-app"); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + + + assertThat(rest.get("http://localhost:8080/simple-app/status/ping"),is("ok")); + + + } + + + +} diff --git a/micro-grizzly-with-jersey/src/test/java/app/simple/com/oath/micro/server/SimpleStatusResource.java b/micro-grizzly-with-jersey/src/test/java/app/simple/com/oath/micro/server/SimpleStatusResource.java new file mode 100644 index 000000000..2a894a8fc --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/simple/com/oath/micro/server/SimpleStatusResource.java @@ -0,0 +1,39 @@ +package app.simple.com.oath.micro.server; + +import java.io.InputStream; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +import org.glassfish.jersey.media.multipart.FormDataContentDisposition; +import org.glassfish.jersey.media.multipart.FormDataParam; + +import com.oath.micro.server.auto.discovery.Rest; + +@Rest +@Path("/status") +public class SimpleStatusResource { + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + + return "ok"; + } + + @POST + @Consumes(MediaType.MULTIPART_FORM_DATA) + @Produces(MediaType.TEXT_PLAIN) + @Path("/file") + public String create( + @FormDataParam("file") InputStream fileInputStream, + @FormDataParam("file") FormDataContentDisposition contentDispositionHeader) { + + return "done"; + } +} \ No newline at end of file diff --git a/micro-grizzly-with-jersey/src/test/java/app/single/com/aol/micro/server/SingleClassTest.java b/micro-grizzly-with-jersey/src/test/java/app/single/com/aol/micro/server/SingleClassTest.java deleted file mode 100644 index d7725eed3..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/single/com/aol/micro/server/SingleClassTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package app.single.com.aol.micro.server; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.RestResource; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.testing.RestAgent; - -@Microserver -@Path("/single") -public class SingleClassTest implements RestResource{ - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer(){ - - server = new MicroserverApp( SingleClassTest.class, ()-> "simple-app"); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - - - assertThat(rest.get("http://localhost:8080/simple-app/single/ping"),is("ok")); - - } - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "ok"; - } - - -} \ No newline at end of file diff --git a/micro-grizzly-with-jersey/src/test/java/app/single/com/oath/micro/server/SingleClassTest.java b/micro-grizzly-with-jersey/src/test/java/app/single/com/oath/micro/server/SingleClassTest.java new file mode 100644 index 000000000..c5a34809d --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/single/com/oath/micro/server/SingleClassTest.java @@ -0,0 +1,58 @@ +package app.single.com.oath.micro.server; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.auto.discovery.RestResource; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.testing.RestAgent; + +@Microserver +@Path("/single") +public class SingleClassTest implements RestResource{ + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer(){ + + server = new MicroserverApp( SingleClassTest.class, ()-> "simple-app"); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + + + assertThat(rest.get("http://localhost:8080/simple-app/single/ping"),is("ok")); + + } + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "ok"; + } + + +} \ No newline at end of file diff --git a/micro-grizzly-with-jersey/src/test/java/app/single/main/com/aol/micro/server/SingleClassApp.java b/micro-grizzly-with-jersey/src/test/java/app/single/main/com/aol/micro/server/SingleClassApp.java deleted file mode 100644 index aef7a170c..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/single/main/com/aol/micro/server/SingleClassApp.java +++ /dev/null @@ -1,24 +0,0 @@ -package app.single.main.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.Rest; - -@Rest -@Path("/status") -public class SingleClassApp { - - public static void main(String[] args){ - new MicroserverApp(()-> "simple-app").run(); - } - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "ok"; - } - -} diff --git a/micro-grizzly-with-jersey/src/test/java/app/single/main/com/oath/micro/server/SingleClassApp.java b/micro-grizzly-with-jersey/src/test/java/app/single/main/com/oath/micro/server/SingleClassApp.java new file mode 100644 index 000000000..2d7a71917 --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/single/main/com/oath/micro/server/SingleClassApp.java @@ -0,0 +1,24 @@ +package app.single.main.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.auto.discovery.Rest; + +@Rest +@Path("/status") +public class SingleClassApp { + + public static void main(String[] args){ + new MicroserverApp(()-> "simple-app").run(); + } + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "ok"; + } + +} diff --git a/micro-grizzly-with-jersey/src/test/java/app/single/serverconfig/com/aol/micro/server/SingleClassTest.java b/micro-grizzly-with-jersey/src/test/java/app/single/serverconfig/com/aol/micro/server/SingleClassTest.java deleted file mode 100644 index af9af9878..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/single/serverconfig/com/aol/micro/server/SingleClassTest.java +++ /dev/null @@ -1,64 +0,0 @@ -package app.single.serverconfig.com.aol.micro.server; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.*; - -import java.util.concurrent.ExecutionException; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.RestResource; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.testing.RestAgent; - - -@Path("/single") -public class SingleClassTest implements RestResource{ - - RestAgent rest = new RestAgent(); - - boolean called; - MicroserverApp server; - @Before - public void startServer(){ - called = false; - server = new MicroserverApp( ConfigurableModule.builder() - .context("hello") - .serverConfigManager(server->called=true) - .build()); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - - - assertThat(rest.get("http://localhost:8080/hello/single/ping"),is("ok")); - assertTrue(called); - - } - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "ok"; - } - - -} \ No newline at end of file diff --git a/micro-grizzly-with-jersey/src/test/java/app/single/serverconfig/com/oath/micro/server/SingleClassTest.java b/micro-grizzly-with-jersey/src/test/java/app/single/serverconfig/com/oath/micro/server/SingleClassTest.java new file mode 100644 index 000000000..4dbcb9705 --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/single/serverconfig/com/oath/micro/server/SingleClassTest.java @@ -0,0 +1,63 @@ +package app.single.serverconfig.com.oath.micro.server; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.*; + +import java.util.concurrent.ExecutionException; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.auto.discovery.RestResource; +import com.oath.micro.server.module.ConfigurableModule; +import com.oath.micro.server.testing.RestAgent; + + +@Path("/single") +public class SingleClassTest implements RestResource{ + + RestAgent rest = new RestAgent(); + + boolean called; + MicroserverApp server; + @Before + public void startServer(){ + called = false; + server = new MicroserverApp( ConfigurableModule.builder() + .context("hello") + .serverConfigManager(server->called=true) + .build()); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + + + assertThat(rest.get("http://localhost:8080/hello/single/ping"),is("ok")); + assertTrue(called); + + } + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "ok"; + } + + +} \ No newline at end of file diff --git a/micro-grizzly-with-jersey/src/test/java/app/spring/com/aol/micro/server/MyBean.java b/micro-grizzly-with-jersey/src/test/java/app/spring/com/aol/micro/server/MyBean.java deleted file mode 100644 index 0663a868d..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/spring/com/aol/micro/server/MyBean.java +++ /dev/null @@ -1,17 +0,0 @@ -package app.spring.com.aol.micro.server; - -import javax.inject.Inject; - -import org.springframework.beans.factory.annotation.Value; - -import lombok.Getter; - -@Getter -public class MyBean { - - public enum One{one,two}; - @Value("${one:one}") - One one; - @Inject - private MyDependency injected; -} diff --git a/micro-grizzly-with-jersey/src/test/java/app/spring/com/aol/micro/server/MyDependency.java b/micro-grizzly-with-jersey/src/test/java/app/spring/com/aol/micro/server/MyDependency.java deleted file mode 100644 index 48d89e6c5..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/spring/com/aol/micro/server/MyDependency.java +++ /dev/null @@ -1,12 +0,0 @@ -package app.spring.com.aol.micro.server; - -import lombok.Getter; - -import org.springframework.stereotype.Component; - -@Component -@Getter -public class MyDependency { - - private String data = "hello world"; -} diff --git a/micro-grizzly-with-jersey/src/test/java/app/spring/com/aol/micro/server/SpringRunnerTest.java b/micro-grizzly-with-jersey/src/test/java/app/spring/com/aol/micro/server/SpringRunnerTest.java deleted file mode 100644 index 1a1765be0..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/spring/com/aol/micro/server/SpringRunnerTest.java +++ /dev/null @@ -1,54 +0,0 @@ -package app.spring.com.aol.micro.server; - - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.springframework.context.annotation.Bean; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.testing.RestAgent; -/**@Configuration -@ComponentScan(basePackages = { "app.spring.com.aol.micro.server" })**/ -@Microserver -public class SpringRunnerTest { - - RestAgent rest = new RestAgent(); - - @Bean - public MyBean mybean(){ - return new MyBean(); - } - - MicroserverApp server; - @Before - public void startServer(){ - - server = new MicroserverApp( SpringRunnerTest.class, ()-> "spring-app"); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void testAutoWiring() throws InterruptedException, ExecutionException{ - - assertThat(rest.get("http://localhost:8080/spring-app/spring/ping"),is("hello world")); - - } - - - - - -} diff --git a/micro-grizzly-with-jersey/src/test/java/app/spring/com/aol/micro/server/SpringStatusResource.java b/micro-grizzly-with-jersey/src/test/java/app/spring/com/aol/micro/server/SpringStatusResource.java deleted file mode 100644 index 331ac997e..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/spring/com/aol/micro/server/SpringStatusResource.java +++ /dev/null @@ -1,32 +0,0 @@ -package app.spring.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.RestResource; - -@Component -@Path("/spring") -public class SpringStatusResource implements RestResource { - - @Autowired - private MyBean mybean; - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return mybean.getInjected().getData(); - } - @GET - @Produces("text/plain") - @Path("/ping2") - public String ping2() { - return "ok"; - } - -} \ No newline at end of file diff --git a/micro-grizzly-with-jersey/src/test/java/app/spring/com/oath/micro/server/MyBean.java b/micro-grizzly-with-jersey/src/test/java/app/spring/com/oath/micro/server/MyBean.java new file mode 100644 index 000000000..7c91f79fb --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/spring/com/oath/micro/server/MyBean.java @@ -0,0 +1,17 @@ +package app.spring.com.oath.micro.server; + +import javax.inject.Inject; + +import org.springframework.beans.factory.annotation.Value; + +import lombok.Getter; + +@Getter +public class MyBean { + + public enum One{one,two}; + @Value("${one:one}") + One one; + @Inject + private MyDependency injected; +} diff --git a/micro-grizzly-with-jersey/src/test/java/app/spring/com/oath/micro/server/MyDependency.java b/micro-grizzly-with-jersey/src/test/java/app/spring/com/oath/micro/server/MyDependency.java new file mode 100644 index 000000000..1ca23b15b --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/spring/com/oath/micro/server/MyDependency.java @@ -0,0 +1,12 @@ +package app.spring.com.oath.micro.server; + +import lombok.Getter; + +import org.springframework.stereotype.Component; + +@Component +@Getter +public class MyDependency { + + private String data = "hello world"; +} diff --git a/micro-grizzly-with-jersey/src/test/java/app/spring/com/oath/micro/server/SpringRunnerTest.java b/micro-grizzly-with-jersey/src/test/java/app/spring/com/oath/micro/server/SpringRunnerTest.java new file mode 100644 index 000000000..d45d0c0e1 --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/spring/com/oath/micro/server/SpringRunnerTest.java @@ -0,0 +1,54 @@ +package app.spring.com.oath.micro.server; + + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.springframework.context.annotation.Bean; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.testing.RestAgent; +/**@Configuration +@ComponentScan(basePackages = { "app.spring.com.aol.micro.server" })**/ +@Microserver +public class SpringRunnerTest { + + RestAgent rest = new RestAgent(); + + @Bean + public MyBean mybean(){ + return new MyBean(); + } + + MicroserverApp server; + @Before + public void startServer(){ + + server = new MicroserverApp( SpringRunnerTest.class, ()-> "spring-app"); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void testAutoWiring() throws InterruptedException, ExecutionException{ + + assertThat(rest.get("http://localhost:8080/spring-app/spring/ping"),is("hello world")); + + } + + + + + +} diff --git a/micro-grizzly-with-jersey/src/test/java/app/spring/com/oath/micro/server/SpringStatusResource.java b/micro-grizzly-with-jersey/src/test/java/app/spring/com/oath/micro/server/SpringStatusResource.java new file mode 100644 index 000000000..ae0c817de --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/spring/com/oath/micro/server/SpringStatusResource.java @@ -0,0 +1,32 @@ +package app.spring.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.RestResource; + +@Component +@Path("/spring") +public class SpringStatusResource implements RestResource { + + @Autowired + private MyBean mybean; + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return mybean.getInjected().getData(); + } + @GET + @Produces("text/plain") + @Path("/ping2") + public String ping2() { + return "ok"; + } + +} \ No newline at end of file diff --git a/micro-grizzly-with-jersey/src/test/java/app/validation/com/aol/micro/server/ImmutableEntity.java b/micro-grizzly-with-jersey/src/test/java/app/validation/com/aol/micro/server/ImmutableEntity.java deleted file mode 100644 index 5b454305d..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/validation/com/aol/micro/server/ImmutableEntity.java +++ /dev/null @@ -1,28 +0,0 @@ -package app.validation.com.aol.micro.server; - - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Builder; - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "") -@XmlRootElement(name = "immutable") -@Getter -@AllArgsConstructor -@Builder -public class ImmutableEntity { - - private final String value; - - - public ImmutableEntity() { - this(null); - } - -} diff --git a/micro-grizzly-with-jersey/src/test/java/app/validation/com/aol/micro/server/ValidationAppResource.java b/micro-grizzly-with-jersey/src/test/java/app/validation/com/aol/micro/server/ValidationAppResource.java deleted file mode 100644 index 880c619e8..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/validation/com/aol/micro/server/ValidationAppResource.java +++ /dev/null @@ -1,23 +0,0 @@ -package app.validation.com.aol.micro.server; - -import javax.validation.constraints.NotNull; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.RestResource; -@Component -@Path("/status") -public class ValidationAppResource implements RestResource { - - @POST - @Produces("application/json") - @Path("/ping") - public ImmutableEntity ping( @NotNull ImmutableEntity entity) { - return entity; - } - - -} diff --git a/micro-grizzly-with-jersey/src/test/java/app/validation/com/aol/micro/server/ValidationAppTest.java b/micro-grizzly-with-jersey/src/test/java/app/validation/com/aol/micro/server/ValidationAppTest.java deleted file mode 100644 index 8cd76c3de..000000000 --- a/micro-grizzly-with-jersey/src/test/java/app/validation/com/aol/micro/server/ValidationAppTest.java +++ /dev/null @@ -1,71 +0,0 @@ -package app.validation.com.aol.micro.server; - -import java.util.concurrent.ExecutionException; - -import javax.ws.rs.BadRequestException; - -import com.oath.cyclops.types.futurestream.SimpleReactStream; -import cyclops.async.SimpleReact; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.testing.RestAgent; - -//@Microserver(basePackages = { "app.guava.com.aol.micro.server" }) -public class ValidationAppTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - - ImmutableEntity entity; - - - SimpleReact simpleReact = new SimpleReact(); - SimpleReactStream stream; - - @Before - public void startServer() { - stream = simpleReact.ofAsync( - () -> server = new MicroserverApp(() -> "guava-app")).then(server -> server.start()); - - entity = ImmutableEntity.builder().value("value").build(); - - - } - - @After - public void stopServer() { - server.stop(); - } - - - @Test(expected=BadRequestException.class) - public void confirmError() throws InterruptedException, - ExecutionException { - - stream.block(); - rest.post( - "http://localhost:8080/guava-app/status/ping", null, - ImmutableEntity.class); - - - } - @Test - public void confirmNoError() throws InterruptedException, - ExecutionException { - - stream.block(); - rest.post( - "http://localhost:8080/guava-app/status/ping", entity, - ImmutableEntity.class); - - - } - - - -} diff --git a/micro-grizzly-with-jersey/src/test/java/app/validation/com/oath/micro/server/ImmutableEntity.java b/micro-grizzly-with-jersey/src/test/java/app/validation/com/oath/micro/server/ImmutableEntity.java new file mode 100644 index 000000000..19e8f5b26 --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/validation/com/oath/micro/server/ImmutableEntity.java @@ -0,0 +1,28 @@ +package app.validation.com.oath.micro.server; + + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Builder; + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "") +@XmlRootElement(name = "immutable") +@Getter +@AllArgsConstructor +@Builder +public class ImmutableEntity { + + private final String value; + + + public ImmutableEntity() { + this(null); + } + +} diff --git a/micro-grizzly-with-jersey/src/test/java/app/validation/com/oath/micro/server/ValidationAppResource.java b/micro-grizzly-with-jersey/src/test/java/app/validation/com/oath/micro/server/ValidationAppResource.java new file mode 100644 index 000000000..7a8d0c325 --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/validation/com/oath/micro/server/ValidationAppResource.java @@ -0,0 +1,23 @@ +package app.validation.com.oath.micro.server; + +import javax.validation.constraints.NotNull; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.RestResource; +@Component +@Path("/status") +public class ValidationAppResource implements RestResource { + + @POST + @Produces("application/json") + @Path("/ping") + public ImmutableEntity ping( @NotNull ImmutableEntity entity) { + return entity; + } + + +} diff --git a/micro-grizzly-with-jersey/src/test/java/app/validation/com/oath/micro/server/ValidationAppTest.java b/micro-grizzly-with-jersey/src/test/java/app/validation/com/oath/micro/server/ValidationAppTest.java new file mode 100644 index 000000000..d209491df --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/app/validation/com/oath/micro/server/ValidationAppTest.java @@ -0,0 +1,71 @@ +package app.validation.com.oath.micro.server; + +import java.util.concurrent.ExecutionException; + +import javax.ws.rs.BadRequestException; + +import com.oath.cyclops.types.futurestream.SimpleReactStream; +import cyclops.async.SimpleReact; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.testing.RestAgent; + +//@Microserver(basePackages = { "app.guava.com.oath.micro.server" }) +public class ValidationAppTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + + ImmutableEntity entity; + + + SimpleReact simpleReact = new SimpleReact(); + SimpleReactStream stream; + + @Before + public void startServer() { + stream = simpleReact.ofAsync( + () -> server = new MicroserverApp(() -> "guava-app")).then(server -> server.start()); + + entity = ImmutableEntity.builder().value("value").build(); + + + } + + @After + public void stopServer() { + server.stop(); + } + + + @Test(expected=BadRequestException.class) + public void confirmError() throws InterruptedException, + ExecutionException { + + stream.block(); + rest.post( + "http://localhost:8080/guava-app/status/ping", null, + ImmutableEntity.class); + + + } + @Test + public void confirmNoError() throws InterruptedException, + ExecutionException { + + stream.block(); + rest.post( + "http://localhost:8080/guava-app/status/ping", entity, + ImmutableEntity.class); + + + } + + + +} diff --git a/micro-grizzly-with-jersey/src/test/java/com/aol/micro/server/testing/RestAgent.java b/micro-grizzly-with-jersey/src/test/java/com/aol/micro/server/testing/RestAgent.java deleted file mode 100644 index ce204f810..000000000 --- a/micro-grizzly-with-jersey/src/test/java/com/aol/micro/server/testing/RestAgent.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.aol.micro.server.testing; - -import java.util.List; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.Invocation.Builder; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; - -import com.aol.micro.server.rest.jackson.JacksonUtil; - -public class RestAgent { - - - public String getJson(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.get(String.class); - - } - - public String get(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.TEXT_PLAIN); - - return request.get(String.class); - - } - - public T post(String url, Object payload,Class type) { - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); - } - - -} diff --git a/micro-grizzly-with-jersey/src/test/java/com/oath/micro/server/testing/RestAgent.java b/micro-grizzly-with-jersey/src/test/java/com/oath/micro/server/testing/RestAgent.java new file mode 100644 index 000000000..b2b86303e --- /dev/null +++ b/micro-grizzly-with-jersey/src/test/java/com/oath/micro/server/testing/RestAgent.java @@ -0,0 +1,53 @@ +package com.oath.micro.server.testing; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.Invocation.Builder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; + +import com.oath.micro.server.rest.jackson.JacksonUtil; + +public class RestAgent { + + + public String getJson(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.get(String.class); + + } + + public String get(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.TEXT_PLAIN); + + return request.get(String.class); + + } + + public T post(String url, Object payload,Class type) { + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); + } + + +} diff --git a/micro-grizzly/src/main/java/com/aol/micro/server/servers/grizzly/GrizzlyApplicationFactory.java b/micro-grizzly/src/main/java/com/aol/micro/server/servers/grizzly/GrizzlyApplicationFactory.java deleted file mode 100644 index 221a5fda0..000000000 --- a/micro-grizzly/src/main/java/com/aol/micro/server/servers/grizzly/GrizzlyApplicationFactory.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.aol.micro.server.servers.grizzly; - -import java.util.List; - -import com.oath.cyclops.types.persistent.PersistentList; -import lombok.AllArgsConstructor; - - -import org.springframework.context.ApplicationContext; - -import com.aol.micro.server.module.Environment; -import com.aol.micro.server.module.Module; -import com.aol.micro.server.module.ModuleDataExtractor; -import com.aol.micro.server.servers.ServerApplication; -import com.aol.micro.server.servers.ServerApplicationFactory; -import com.aol.micro.server.servers.model.AllData; -import com.aol.micro.server.servers.model.FilterData; -import com.aol.micro.server.servers.model.ServerData; -import com.aol.micro.server.servers.model.ServletData; - -@AllArgsConstructor -public class GrizzlyApplicationFactory implements ServerApplicationFactory { - - - - - public ServerApplication createApp(final Module module, final ApplicationContext rootContext) { - ModuleDataExtractor extractor = new ModuleDataExtractor(module); - PersistentList resources = extractor.getRestResources(rootContext); - - Environment environment = rootContext.getBean(Environment.class); - - environment.assureModule(module); - String fullRestResource = "/" + module.getContext() + "/*"; - - ServerData serverData = new ServerData(environment.getModuleBean(module).getPort(), - resources, - rootContext, fullRestResource, module); - List filterDataList = extractor.createFilteredDataList(serverData); - List servletDataList = extractor.createServletDataList(serverData); - - GrizzlyApplication app = new GrizzlyApplication( - new AllData(serverData, - filterDataList, - servletDataList, - module.getListeners(serverData), - module.getRequestListeners(serverData))); - return app; - } -} diff --git a/micro-grizzly/src/main/java/com/aol/micro/server/servers/grizzly/SSLConfigurationBuilder.java b/micro-grizzly/src/main/java/com/aol/micro/server/servers/grizzly/SSLConfigurationBuilder.java deleted file mode 100644 index 3916d6f44..000000000 --- a/micro-grizzly/src/main/java/com/aol/micro/server/servers/grizzly/SSLConfigurationBuilder.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.aol.micro.server.servers.grizzly; - -import cyclops.control.Maybe; -import org.glassfish.grizzly.ssl.SSLContextConfigurator; -import org.glassfish.grizzly.ssl.SSLEngineConfigurator; - -import com.aol.micro.server.config.SSLProperties; - -public class SSLConfigurationBuilder { - - - public SSLEngineConfigurator build(SSLProperties sslProperties) { - - SSLContextConfigurator sslContext = new SSLContextConfigurator(); - - sslContext.setKeyStoreFile(sslProperties.getKeyStoreFile()); // contains server keypair - sslContext.setKeyStorePass(sslProperties.getKeyStorePass()); - - /** - * trustStore stores public key or certificates from CA (Certificate Authorities) - * which is used to trust remote party or SSL connection. So should be optional - */ - sslProperties.getTrustStoreFile().ifPresent(file->sslContext.setTrustStoreFile(file)); // contains client certificate - sslProperties.getTrustStorePass().ifPresent(pass->sslContext.setTrustStorePass(pass)); - - - - sslProperties.getKeyStoreType().ifPresent(type->sslContext.setKeyStoreType(type)); - sslProperties.getKeyStoreProvider().ifPresent(provider->sslContext.setKeyStoreProvider(provider)); - - - sslProperties.getTrustStoreType().ifPresent(type->sslContext.setTrustStoreType(type)); - sslProperties.getTrustStoreProvider().ifPresent(provider->sslContext.setTrustStoreProvider(provider)); - - - - - - SSLEngineConfigurator sslConf = new SSLEngineConfigurator(sslContext).setClientMode(false); - sslProperties.getClientAuth().filter(auth-> auth.toLowerCase().equals("want")) - .ifPresent(auth->sslConf.setWantClientAuth(true)); - sslProperties.getClientAuth().filter(auth-> auth.toLowerCase().equals("need")) - .ifPresent(auth->sslConf.setNeedClientAuth(true)); - Maybe.fromOptional(sslProperties.getCiphers()).peek(ciphers->sslConf.setEnabledCipherSuites(ciphers.split(","))) - .forEach(c-> sslConf.setCipherConfigured(true)); - Maybe.fromOptional(sslProperties.getProtocol()).peek(pr->sslConf.setEnabledProtocols(pr.split(","))) - .forEach(p->sslConf.setProtocolConfigured(true)); - - - return sslConf; - } -} diff --git a/micro-grizzly/src/main/java/com/aol/micro/server/servers/grizzly/plugin/GrizzlyPlugin.java b/micro-grizzly/src/main/java/com/aol/micro/server/servers/grizzly/plugin/GrizzlyPlugin.java deleted file mode 100644 index 97989de8f..000000000 --- a/micro-grizzly/src/main/java/com/aol/micro/server/servers/grizzly/plugin/GrizzlyPlugin.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.aol.micro.server.servers.grizzly.plugin; - -import java.util.Optional; - -import com.aol.micro.server.Plugin; -import com.aol.micro.server.servers.ServerApplicationFactory; -import com.aol.micro.server.servers.grizzly.GrizzlyApplicationFactory; - - -public class GrizzlyPlugin implements Plugin{ - - @Override - public Optional serverApplicationFactory(){ - return Optional.of(new GrizzlyApplicationFactory()); - } - - -} diff --git a/micro-grizzly/src/main/java/com/aol/micro/server/servers/grizzly/GrizzlyApplication.java b/micro-grizzly/src/main/java/com/oath/micro/server/servers/grizzly/GrizzlyApplication.java similarity index 87% rename from micro-grizzly/src/main/java/com/aol/micro/server/servers/grizzly/GrizzlyApplication.java rename to micro-grizzly/src/main/java/com/oath/micro/server/servers/grizzly/GrizzlyApplication.java index 55d9108fb..719983848 100644 --- a/micro-grizzly/src/main/java/com/aol/micro/server/servers/grizzly/GrizzlyApplication.java +++ b/micro-grizzly/src/main/java/com/oath/micro/server/servers/grizzly/GrizzlyApplication.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.servers.grizzly; +package com.oath.micro.server.servers.grizzly; import java.io.IOException; import java.util.concurrent.CompletableFuture; @@ -18,19 +18,19 @@ import org.slf4j.LoggerFactory; -import com.aol.micro.server.InternalErrorCode; -import com.aol.micro.server.config.SSLProperties; -import com.aol.micro.server.module.WebServerProvider; -import com.aol.micro.server.servers.AccessLogLocationBean; -import com.aol.micro.server.servers.FilterConfigurer; -import com.aol.micro.server.servers.JaxRsServletConfigurer; -import com.aol.micro.server.servers.ServerApplication; -import com.aol.micro.server.servers.ServletConfigurer; -import com.aol.micro.server.servers.ServletContextListenerConfigurer; -import com.aol.micro.server.servers.model.AllData; -import com.aol.micro.server.servers.model.FilterData; -import com.aol.micro.server.servers.model.ServerData; -import com.aol.micro.server.servers.model.ServletData; +import com.oath.micro.server.InternalErrorCode; +import com.oath.micro.server.config.SSLProperties; +import com.oath.micro.server.module.WebServerProvider; +import com.oath.micro.server.servers.AccessLogLocationBean; +import com.oath.micro.server.servers.FilterConfigurer; +import com.oath.micro.server.servers.JaxRsServletConfigurer; +import com.oath.micro.server.servers.ServerApplication; +import com.oath.micro.server.servers.ServletConfigurer; +import com.oath.micro.server.servers.ServletContextListenerConfigurer; +import com.oath.micro.server.servers.model.AllData; +import com.oath.micro.server.servers.model.FilterData; +import com.oath.micro.server.servers.model.ServerData; +import com.oath.micro.server.servers.model.ServletData; import lombok.AccessLevel; import lombok.AllArgsConstructor; diff --git a/micro-grizzly/src/main/java/com/oath/micro/server/servers/grizzly/GrizzlyApplicationFactory.java b/micro-grizzly/src/main/java/com/oath/micro/server/servers/grizzly/GrizzlyApplicationFactory.java new file mode 100644 index 000000000..625972f28 --- /dev/null +++ b/micro-grizzly/src/main/java/com/oath/micro/server/servers/grizzly/GrizzlyApplicationFactory.java @@ -0,0 +1,50 @@ +package com.oath.micro.server.servers.grizzly; + +import java.util.List; + +import com.oath.cyclops.types.persistent.PersistentList; +import lombok.AllArgsConstructor; + + +import org.springframework.context.ApplicationContext; + +import com.oath.micro.server.module.Environment; +import com.oath.micro.server.module.Module; +import com.oath.micro.server.module.ModuleDataExtractor; +import com.oath.micro.server.servers.ServerApplication; +import com.oath.micro.server.servers.ServerApplicationFactory; +import com.oath.micro.server.servers.model.AllData; +import com.oath.micro.server.servers.model.FilterData; +import com.oath.micro.server.servers.model.ServerData; +import com.oath.micro.server.servers.model.ServletData; + +@AllArgsConstructor +public class GrizzlyApplicationFactory implements ServerApplicationFactory { + + + + + public ServerApplication createApp(final Module module, final ApplicationContext rootContext) { + ModuleDataExtractor extractor = new ModuleDataExtractor(module); + PersistentList resources = extractor.getRestResources(rootContext); + + Environment environment = rootContext.getBean(Environment.class); + + environment.assureModule(module); + String fullRestResource = "/" + module.getContext() + "/*"; + + ServerData serverData = new ServerData(environment.getModuleBean(module).getPort(), + resources, + rootContext, fullRestResource, module); + List filterDataList = extractor.createFilteredDataList(serverData); + List servletDataList = extractor.createServletDataList(serverData); + + GrizzlyApplication app = new GrizzlyApplication( + new AllData(serverData, + filterDataList, + servletDataList, + module.getListeners(serverData), + module.getRequestListeners(serverData))); + return app; + } +} diff --git a/micro-grizzly/src/main/java/com/oath/micro/server/servers/grizzly/SSLConfigurationBuilder.java b/micro-grizzly/src/main/java/com/oath/micro/server/servers/grizzly/SSLConfigurationBuilder.java new file mode 100644 index 000000000..e043a91f2 --- /dev/null +++ b/micro-grizzly/src/main/java/com/oath/micro/server/servers/grizzly/SSLConfigurationBuilder.java @@ -0,0 +1,52 @@ +package com.oath.micro.server.servers.grizzly; + +import cyclops.control.Maybe; +import org.glassfish.grizzly.ssl.SSLContextConfigurator; +import org.glassfish.grizzly.ssl.SSLEngineConfigurator; + +import com.oath.micro.server.config.SSLProperties; + +public class SSLConfigurationBuilder { + + + public SSLEngineConfigurator build(SSLProperties sslProperties) { + + SSLContextConfigurator sslContext = new SSLContextConfigurator(); + + sslContext.setKeyStoreFile(sslProperties.getKeyStoreFile()); // contains server keypair + sslContext.setKeyStorePass(sslProperties.getKeyStorePass()); + + /** + * trustStore stores public key or certificates from CA (Certificate Authorities) + * which is used to trust remote party or SSL connection. So should be optional + */ + sslProperties.getTrustStoreFile().ifPresent(file->sslContext.setTrustStoreFile(file)); // contains client certificate + sslProperties.getTrustStorePass().ifPresent(pass->sslContext.setTrustStorePass(pass)); + + + + sslProperties.getKeyStoreType().ifPresent(type->sslContext.setKeyStoreType(type)); + sslProperties.getKeyStoreProvider().ifPresent(provider->sslContext.setKeyStoreProvider(provider)); + + + sslProperties.getTrustStoreType().ifPresent(type->sslContext.setTrustStoreType(type)); + sslProperties.getTrustStoreProvider().ifPresent(provider->sslContext.setTrustStoreProvider(provider)); + + + + + + SSLEngineConfigurator sslConf = new SSLEngineConfigurator(sslContext).setClientMode(false); + sslProperties.getClientAuth().filter(auth-> auth.toLowerCase().equals("want")) + .ifPresent(auth->sslConf.setWantClientAuth(true)); + sslProperties.getClientAuth().filter(auth-> auth.toLowerCase().equals("need")) + .ifPresent(auth->sslConf.setNeedClientAuth(true)); + Maybe.fromOptional(sslProperties.getCiphers()).peek(ciphers->sslConf.setEnabledCipherSuites(ciphers.split(","))) + .forEach(c-> sslConf.setCipherConfigured(true)); + Maybe.fromOptional(sslProperties.getProtocol()).peek(pr->sslConf.setEnabledProtocols(pr.split(","))) + .forEach(p->sslConf.setProtocolConfigured(true)); + + + return sslConf; + } +} diff --git a/micro-grizzly/src/main/java/com/oath/micro/server/servers/grizzly/plugin/GrizzlyPlugin.java b/micro-grizzly/src/main/java/com/oath/micro/server/servers/grizzly/plugin/GrizzlyPlugin.java new file mode 100644 index 000000000..13ff94f0a --- /dev/null +++ b/micro-grizzly/src/main/java/com/oath/micro/server/servers/grizzly/plugin/GrizzlyPlugin.java @@ -0,0 +1,18 @@ +package com.oath.micro.server.servers.grizzly.plugin; + +import java.util.Optional; + +import com.oath.micro.server.Plugin; +import com.oath.micro.server.servers.ServerApplicationFactory; +import com.oath.micro.server.servers.grizzly.GrizzlyApplicationFactory; + + +public class GrizzlyPlugin implements Plugin{ + + @Override + public Optional serverApplicationFactory(){ + return Optional.of(new GrizzlyApplicationFactory()); + } + + +} diff --git a/micro-grizzly/src/main/resources/META-INF/services/com.aol.micro.server.Plugin b/micro-grizzly/src/main/resources/META-INF/services/com.aol.micro.server.Plugin deleted file mode 100644 index 6456cfd54..000000000 --- a/micro-grizzly/src/main/resources/META-INF/services/com.aol.micro.server.Plugin +++ /dev/null @@ -1 +0,0 @@ -com.aol.micro.server.servers.grizzly.plugin.GrizzlyPlugin \ No newline at end of file diff --git a/micro-grizzly/src/main/resources/META-INF/services/com.oath.micro.server.Plugin b/micro-grizzly/src/main/resources/META-INF/services/com.oath.micro.server.Plugin new file mode 100644 index 000000000..c32dea54f --- /dev/null +++ b/micro-grizzly/src/main/resources/META-INF/services/com.oath.micro.server.Plugin @@ -0,0 +1 @@ +com.oath.micro.server.servers.grizzly.plugin.GrizzlyPlugin \ No newline at end of file diff --git a/micro-grizzly/src/test/java/app/access/log/micro/server/servers/AccessLogConfigTest.java b/micro-grizzly/src/test/java/app/access/log/micro/server/servers/AccessLogConfigTest.java index 177e8d52f..6bea5bf8a 100644 --- a/micro-grizzly/src/test/java/app/access/log/micro/server/servers/AccessLogConfigTest.java +++ b/micro-grizzly/src/test/java/app/access/log/micro/server/servers/AccessLogConfigTest.java @@ -11,8 +11,8 @@ import org.junit.Before; import org.junit.Test; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; @Microserver(properties={"access.log.output", "${user.home}"}) public class AccessLogConfigTest { diff --git a/micro-grizzly/src/test/java/app/async/com/aol/micro/server/AsyncAppRunner.java b/micro-grizzly/src/test/java/app/async/com/aol/micro/server/AsyncAppRunner.java deleted file mode 100644 index e4150644d..000000000 --- a/micro-grizzly/src/test/java/app/async/com/aol/micro/server/AsyncAppRunner.java +++ /dev/null @@ -1,58 +0,0 @@ -package app.async.com.aol.micro.server; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.io.IOException; -import java.util.Properties; -import java.util.concurrent.ExecutionException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.spring.properties.PropertyFileConfig; -import com.aol.micro.server.testing.RestAgent; - -@Microserver -public class AsyncAppRunner { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - - @Before - public void startServer() { - - server = new MicroserverApp( - () -> "async-app"); - server.start(); - - } - - @After - public void stopServer() { - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException { - - Thread.sleep(2000); - - assertThat(rest.get("http://localhost:8080/async-app/async/expensive"), is(";test!;test!;test!")); - - } - - @Test - public void loadProperties() throws IOException { - - Properties props = new PropertyFileConfig( - true).propertyFactory(); - assertThat(props.getProperty("test"), is("hello world")); - assertThat(props.getProperty("override"), is("boo!")); - } - -} \ No newline at end of file diff --git a/micro-grizzly/src/test/java/app/async/com/aol/micro/server/AsyncResource.java b/micro-grizzly/src/test/java/app/async/com/aol/micro/server/AsyncResource.java deleted file mode 100644 index c8d0add5e..000000000 --- a/micro-grizzly/src/test/java/app/async/com/aol/micro/server/AsyncResource.java +++ /dev/null @@ -1,56 +0,0 @@ -package app.async.com.aol.micro.server; - -import java.util.Arrays; -import java.util.List; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.container.AsyncResponse; -import javax.ws.rs.container.Suspended; - -import cyclops.async.SimpleReact; -import cyclops.reactive.FutureStream; -import cyclops.reactive.ReactiveSeq; -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.RestResource; -import com.aol.micro.server.testing.RestAgent; - -@Path("/async") -@Component -public class AsyncResource implements RestResource{ - - private final SimpleReact simpleReact =new SimpleReact(); - private final List urls = Arrays.asList("http://localhost:8080/async-app/async/ping2", - "http://localhost:8080/async-app/async/ping", - "http://localhost:8080/async-app/async/ping", - "http://localhost:8080/async-app/async/ping"); - - private final RestAgent client = new RestAgent(); - - @GET - @Path("/expensive") - @Produces("text/plain") - public void expensive(@Suspended AsyncResponse asyncResponse){ - - FutureStream.builder().fromIterable(urls) - .then(it->client.get(it)) - .onFail(it -> "") - .peek(it -> - System.out.println(it)) - .convertToSimpleReact() - .allOf(data -> { - System.out.println(data); - return asyncResponse.resume(ReactiveSeq.fromIterable(data).join(";")); }); - } - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "test!"; - } - - -} diff --git a/micro-grizzly/src/test/java/app/async/com/aol/micro/server/Simple.java b/micro-grizzly/src/test/java/app/async/com/aol/micro/server/Simple.java deleted file mode 100644 index edefa80ef..000000000 --- a/micro-grizzly/src/test/java/app/async/com/aol/micro/server/Simple.java +++ /dev/null @@ -1,16 +0,0 @@ -package app.async.com.aol.micro.server; - -import java.io.IOException; -import java.util.Properties; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Config; -import com.aol.micro.server.spring.properties.PropertyFileConfig; - -public class Simple { - - public static void main(String[] args) throws IOException{ - - new MicroserverApp(()->"test-app").run(); - } -} diff --git a/micro-grizzly/src/test/java/app/async/com/aol/micro/server/SimpleApp.java b/micro-grizzly/src/test/java/app/async/com/aol/micro/server/SimpleApp.java deleted file mode 100644 index 919b7c6b0..000000000 --- a/micro-grizzly/src/test/java/app/async/com/aol/micro/server/SimpleApp.java +++ /dev/null @@ -1,24 +0,0 @@ -package app.async.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.Rest; - - - -@Rest -@Path("/test") -public class SimpleApp { - - public static void main(String[] args){ - new MicroserverApp(()->"test-app").run(); - } - @GET - public String myEndPoint(){ - return "hello world!"; - } - - -} diff --git a/micro-grizzly/src/test/java/app/async/com/oath/micro/server/AsyncAppRunner.java b/micro-grizzly/src/test/java/app/async/com/oath/micro/server/AsyncAppRunner.java new file mode 100644 index 000000000..5d6ea0ea7 --- /dev/null +++ b/micro-grizzly/src/test/java/app/async/com/oath/micro/server/AsyncAppRunner.java @@ -0,0 +1,58 @@ +package app.async.com.oath.micro.server; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.io.IOException; +import java.util.Properties; +import java.util.concurrent.ExecutionException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.spring.properties.PropertyFileConfig; +import com.oath.micro.server.testing.RestAgent; + +@Microserver +public class AsyncAppRunner { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + + @Before + public void startServer() { + + server = new MicroserverApp( + () -> "async-app"); + server.start(); + + } + + @After + public void stopServer() { + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException { + + Thread.sleep(2000); + + assertThat(rest.get("http://localhost:8080/async-app/async/expensive"), is(";test!;test!;test!")); + + } + + @Test + public void loadProperties() throws IOException { + + Properties props = new PropertyFileConfig( + true).propertyFactory(); + assertThat(props.getProperty("test"), is("hello world")); + assertThat(props.getProperty("override"), is("boo!")); + } + +} \ No newline at end of file diff --git a/micro-grizzly/src/test/java/app/async/com/oath/micro/server/AsyncResource.java b/micro-grizzly/src/test/java/app/async/com/oath/micro/server/AsyncResource.java new file mode 100644 index 000000000..67306d213 --- /dev/null +++ b/micro-grizzly/src/test/java/app/async/com/oath/micro/server/AsyncResource.java @@ -0,0 +1,56 @@ +package app.async.com.oath.micro.server; + +import java.util.Arrays; +import java.util.List; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.container.AsyncResponse; +import javax.ws.rs.container.Suspended; + +import cyclops.async.SimpleReact; +import cyclops.reactive.FutureStream; +import cyclops.reactive.ReactiveSeq; +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.RestResource; +import com.oath.micro.server.testing.RestAgent; + +@Path("/async") +@Component +public class AsyncResource implements RestResource{ + + private final SimpleReact simpleReact =new SimpleReact(); + private final List urls = Arrays.asList("http://localhost:8080/async-app/async/ping2", + "http://localhost:8080/async-app/async/ping", + "http://localhost:8080/async-app/async/ping", + "http://localhost:8080/async-app/async/ping"); + + private final RestAgent client = new RestAgent(); + + @GET + @Path("/expensive") + @Produces("text/plain") + public void expensive(@Suspended AsyncResponse asyncResponse){ + + FutureStream.builder().fromIterable(urls) + .then(it->client.get(it)) + .onFail(it -> "") + .peek(it -> + System.out.println(it)) + .convertToSimpleReact() + .allOf(data -> { + System.out.println(data); + return asyncResponse.resume(ReactiveSeq.fromIterable(data).join(";")); }); + } + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "test!"; + } + + +} diff --git a/micro-grizzly/src/test/java/app/async/com/oath/micro/server/Simple.java b/micro-grizzly/src/test/java/app/async/com/oath/micro/server/Simple.java new file mode 100644 index 000000000..3eb3e7504 --- /dev/null +++ b/micro-grizzly/src/test/java/app/async/com/oath/micro/server/Simple.java @@ -0,0 +1,13 @@ +package app.async.com.oath.micro.server; + +import java.io.IOException; + +import com.oath.micro.server.MicroserverApp; + +public class Simple { + + public static void main(String[] args) throws IOException{ + + new MicroserverApp(()->"test-app").run(); + } +} diff --git a/micro-grizzly/src/test/java/app/async/com/oath/micro/server/SimpleApp.java b/micro-grizzly/src/test/java/app/async/com/oath/micro/server/SimpleApp.java new file mode 100644 index 000000000..916d0330e --- /dev/null +++ b/micro-grizzly/src/test/java/app/async/com/oath/micro/server/SimpleApp.java @@ -0,0 +1,24 @@ +package app.async.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.auto.discovery.Rest; + + + +@Rest +@Path("/test") +public class SimpleApp { + + public static void main(String[] args){ + new MicroserverApp(()->"test-app").run(); + } + @GET + public String myEndPoint(){ + return "hello world!"; + } + + +} diff --git a/micro-grizzly/src/test/java/app/custom/binder/test/SimpleApp.java b/micro-grizzly/src/test/java/app/custom/binder/test/SimpleApp.java index 7a2c74e08..2e275f0bd 100644 --- a/micro-grizzly/src/test/java/app/custom/binder/test/SimpleApp.java +++ b/micro-grizzly/src/test/java/app/custom/binder/test/SimpleApp.java @@ -5,9 +5,9 @@ import org.glassfish.jersey.server.ResourceConfig; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.module.ConfigurableModule; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.auto.discovery.Rest; +import com.oath.micro.server.module.ConfigurableModule; diff --git a/micro-grizzly/src/test/java/app/embedded/com/aol/micro/server/AltAppResource.java b/micro-grizzly/src/test/java/app/embedded/com/aol/micro/server/AltAppResource.java deleted file mode 100644 index d4b8eff5c..000000000 --- a/micro-grizzly/src/test/java/app/embedded/com/aol/micro/server/AltAppResource.java +++ /dev/null @@ -1,23 +0,0 @@ -package app.embedded.com.aol.micro.server; - -import java.util.ArrayList; -import java.util.List; - -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.stereotype.Component; - -@Component -@Path("/alt-status") -public class AltAppResource implements AltAppRestResource { - - @POST - @Produces("application/json") - @Path("/ping") - public List ping(ImmutableEntity entity) { - return entity.getList(); - } - -} diff --git a/micro-grizzly/src/test/java/app/embedded/com/aol/micro/server/AltAppRestResource.java b/micro-grizzly/src/test/java/app/embedded/com/aol/micro/server/AltAppRestResource.java deleted file mode 100644 index 8cb2643e3..000000000 --- a/micro-grizzly/src/test/java/app/embedded/com/aol/micro/server/AltAppRestResource.java +++ /dev/null @@ -1,7 +0,0 @@ -package app.embedded.com.aol.micro.server; - -import com.aol.micro.server.auto.discovery.RestResource; - -public interface AltAppRestResource extends RestResource { - -} diff --git a/micro-grizzly/src/test/java/app/embedded/com/aol/micro/server/EmbeddedAppLocalMain.java b/micro-grizzly/src/test/java/app/embedded/com/aol/micro/server/EmbeddedAppLocalMain.java deleted file mode 100644 index 9e602c91c..000000000 --- a/micro-grizzly/src/test/java/app/embedded/com/aol/micro/server/EmbeddedAppLocalMain.java +++ /dev/null @@ -1,22 +0,0 @@ -package app.embedded.com.aol.micro.server; - -import java.util.Arrays; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.module.EmbeddedModule; - -@Microserver(basePackages = { "app.embedded.com.aol.micro.server" }) -public class EmbeddedAppLocalMain { - - - public static void main(String[] args) throws InterruptedException { - - new MicroserverApp( - EmbeddedModule.tagInterfaceModule(Arrays.asList(TestAppRestResource.class),"test-app"), - EmbeddedModule.tagInterfaceModule(Arrays.asList(AltAppRestResource.class),"alternative-app")).start(); - - } - - -} diff --git a/micro-grizzly/src/test/java/app/embedded/com/aol/micro/server/EmbeddedAppTest.java b/micro-grizzly/src/test/java/app/embedded/com/aol/micro/server/EmbeddedAppTest.java deleted file mode 100644 index 47228dc0b..000000000 --- a/micro-grizzly/src/test/java/app/embedded/com/aol/micro/server/EmbeddedAppTest.java +++ /dev/null @@ -1,102 +0,0 @@ -package app.embedded.com.aol.micro.server; - -import static org.hamcrest.Matchers.hasItem; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; - -import javax.ws.rs.NotFoundException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.springframework.util.concurrent.ListenableFuture; -import org.springframework.util.concurrent.ListenableFutureCallback; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.module.EmbeddedModule; -import com.aol.micro.server.testing.RestAgent; - -public class EmbeddedAppTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - - @Before - public void startServer(){ - server = new MicroserverApp(EmbeddedAppLocalMain.class, - EmbeddedModule.tagInterfaceModule(Arrays.asList(TestAppRestResource.class),"test-app"), - EmbeddedModule.tagInterfaceModule(Arrays.asList(AltAppRestResource.class),"alternative-app")); - server.start(); - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void confirmExpectedUrlsPresentTest() throws InterruptedException, ExecutionException{ - - assertThat(rest.get("http://localhost:8080/test-app/test-status/ping"),is("test!")); - - - assertThat((List)rest.post("http://localhost:8081/alternative-app/alt-status/ping",new ImmutableEntity("value",Arrays.asList("hello","world")),List.class), - hasItem("hello")); - - } - - - @Test - public void nonBlockingRestClientTest(){ - assertThat(rest.get("http://localhost:8080/test-app/test-status/rest-calls"),is("-*test!-*test!")); - } - - CompletableFuture toCompletableFuture( - final ListenableFuture listenableFuture - ) { - //create an instance of CompletableFuture - CompletableFuture completable = new CompletableFuture() { - @Override - public boolean cancel(boolean mayInterruptIfRunning) { - // propagate cancel to the listenable future - boolean result = listenableFuture.cancel(mayInterruptIfRunning); - super.cancel(mayInterruptIfRunning); - return result; - } - }; - - // add callback - listenableFuture.addCallback(new ListenableFutureCallback() { - @Override - public void onSuccess(T result) { - completable.complete(result); - } - - @Override - public void onFailure(Throwable t) { - completable.completeExceptionally(t); - } - }); - return completable; - } - - @Test(expected=NotFoundException.class) - public void confirmAltAppCantUseTestAppResources(){ - - assertThat(rest.get("http://localhost:8080/alternative-app/test-status/ping"),is("test!")); - - } - @Test(expected=NotFoundException.class) - public void confirmTestAppCantUseAltAppResources(){ - - assertThat((List)rest.post("http://localhost:8081/test-app/alt-status/ping",new ImmutableEntity("value",Arrays.asList("hello","world")),List.class), - hasItem("hello")); - - } -} diff --git a/micro-grizzly/src/test/java/app/embedded/com/aol/micro/server/ImmutableEntity.java b/micro-grizzly/src/test/java/app/embedded/com/aol/micro/server/ImmutableEntity.java deleted file mode 100644 index cd593f123..000000000 --- a/micro-grizzly/src/test/java/app/embedded/com/aol/micro/server/ImmutableEntity.java +++ /dev/null @@ -1,29 +0,0 @@ -package app.embedded.com.aol.micro.server; - -import java.util.List; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Builder; - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "") -@XmlRootElement(name = "immutable") -@Getter -@AllArgsConstructor -@Builder -public class ImmutableEntity { - - private final String value; - private final List list; - - public ImmutableEntity() { - this(null,null); - } - -} diff --git a/micro-grizzly/src/test/java/app/embedded/com/aol/micro/server/TestAppResource.java b/micro-grizzly/src/test/java/app/embedded/com/aol/micro/server/TestAppResource.java deleted file mode 100644 index 24c0ebe27..000000000 --- a/micro-grizzly/src/test/java/app/embedded/com/aol/micro/server/TestAppResource.java +++ /dev/null @@ -1,49 +0,0 @@ -package app.embedded.com.aol.micro.server; - -import java.util.Arrays; -import java.util.List; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import cyclops.async.SimpleReact; -import cyclops.reactive.FutureStream; -import org.springframework.stereotype.Component; - - -import com.aol.micro.server.testing.RestAgent; -@Component -@Path("/test-status") -public class TestAppResource implements TestAppRestResource { - - private final SimpleReact simpleReact = new SimpleReact(); - private final RestAgent template = new RestAgent(); - private final List urls = Arrays.asList("http://localhost:8081/alternative-app/alt-status/ping", - "http://localhost:8080/test-app/test-status/ping", - "http://localhost:8082/simple-app/status/ping", - "http://localhost:8080/test-app/test-status/ping"); - - - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "test!"; - } - - @GET - @Produces("text/plain") - @Path("/rest-calls") - public String restCallResult(){ - - return FutureStream.builder().fromIterable(urls) - .map(it ->template.get(it)) - .then(it -> "*"+it) - .peek(loadedAndModified -> System.out.println(loadedAndModified)) - .block().stream().reduce("", (acc,next) -> acc+"-"+next); - - } - -} diff --git a/micro-grizzly/src/test/java/app/embedded/com/aol/micro/server/TestAppRestResource.java b/micro-grizzly/src/test/java/app/embedded/com/aol/micro/server/TestAppRestResource.java deleted file mode 100644 index 3133fd8cc..000000000 --- a/micro-grizzly/src/test/java/app/embedded/com/aol/micro/server/TestAppRestResource.java +++ /dev/null @@ -1,7 +0,0 @@ -package app.embedded.com.aol.micro.server; - -import com.aol.micro.server.auto.discovery.RestResource; - -public interface TestAppRestResource extends RestResource { - -} diff --git a/micro-grizzly/src/test/java/app/embedded/com/oath/micro/server/AltAppResource.java b/micro-grizzly/src/test/java/app/embedded/com/oath/micro/server/AltAppResource.java new file mode 100644 index 000000000..1835ababe --- /dev/null +++ b/micro-grizzly/src/test/java/app/embedded/com/oath/micro/server/AltAppResource.java @@ -0,0 +1,22 @@ +package app.embedded.com.oath.micro.server; + +import java.util.List; + +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.stereotype.Component; + +@Component +@Path("/alt-status") +public class AltAppResource implements AltAppRestResource { + + @POST + @Produces("application/json") + @Path("/ping") + public List ping(ImmutableEntity entity) { + return entity.getList(); + } + +} diff --git a/micro-grizzly/src/test/java/app/embedded/com/oath/micro/server/AltAppRestResource.java b/micro-grizzly/src/test/java/app/embedded/com/oath/micro/server/AltAppRestResource.java new file mode 100644 index 000000000..7045a4f35 --- /dev/null +++ b/micro-grizzly/src/test/java/app/embedded/com/oath/micro/server/AltAppRestResource.java @@ -0,0 +1,7 @@ +package app.embedded.com.oath.micro.server; + +import com.oath.micro.server.auto.discovery.RestResource; + +public interface AltAppRestResource extends RestResource { + +} diff --git a/micro-grizzly/src/test/java/app/embedded/com/oath/micro/server/EmbeddedAppLocalMain.java b/micro-grizzly/src/test/java/app/embedded/com/oath/micro/server/EmbeddedAppLocalMain.java new file mode 100644 index 000000000..0a38613b7 --- /dev/null +++ b/micro-grizzly/src/test/java/app/embedded/com/oath/micro/server/EmbeddedAppLocalMain.java @@ -0,0 +1,22 @@ +package app.embedded.com.oath.micro.server; + +import java.util.Arrays; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.module.EmbeddedModule; + +@Microserver(basePackages = { "app.embedded.com.oath.micro.server" }) +public class EmbeddedAppLocalMain { + + + public static void main(String[] args) throws InterruptedException { + + new MicroserverApp( + EmbeddedModule.tagInterfaceModule(Arrays.asList(TestAppRestResource.class),"test-app"), + EmbeddedModule.tagInterfaceModule(Arrays.asList(AltAppRestResource.class),"alternative-app")).start(); + + } + + +} diff --git a/micro-grizzly/src/test/java/app/embedded/com/oath/micro/server/EmbeddedAppTest.java b/micro-grizzly/src/test/java/app/embedded/com/oath/micro/server/EmbeddedAppTest.java new file mode 100644 index 000000000..83eb220c1 --- /dev/null +++ b/micro-grizzly/src/test/java/app/embedded/com/oath/micro/server/EmbeddedAppTest.java @@ -0,0 +1,102 @@ +package app.embedded.com.oath.micro.server; + +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; + +import javax.ws.rs.NotFoundException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.springframework.util.concurrent.ListenableFuture; +import org.springframework.util.concurrent.ListenableFutureCallback; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.module.EmbeddedModule; +import com.oath.micro.server.testing.RestAgent; + +public class EmbeddedAppTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + + @Before + public void startServer(){ + server = new MicroserverApp(EmbeddedAppLocalMain.class, + EmbeddedModule.tagInterfaceModule(Arrays.asList(TestAppRestResource.class),"test-app"), + EmbeddedModule.tagInterfaceModule(Arrays.asList(AltAppRestResource.class),"alternative-app")); + server.start(); + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void confirmExpectedUrlsPresentTest() throws InterruptedException, ExecutionException{ + + assertThat(rest.get("http://localhost:8080/test-app/test-status/ping"),is("test!")); + + + assertThat((List)rest.post("http://localhost:8081/alternative-app/alt-status/ping",new ImmutableEntity("value",Arrays.asList("hello","world")),List.class), + hasItem("hello")); + + } + + + @Test + public void nonBlockingRestClientTest(){ + assertThat(rest.get("http://localhost:8080/test-app/test-status/rest-calls"),is("-*test!-*test!")); + } + + CompletableFuture toCompletableFuture( + final ListenableFuture listenableFuture + ) { + //create an instance of CompletableFuture + CompletableFuture completable = new CompletableFuture() { + @Override + public boolean cancel(boolean mayInterruptIfRunning) { + // propagate cancel to the listenable future + boolean result = listenableFuture.cancel(mayInterruptIfRunning); + super.cancel(mayInterruptIfRunning); + return result; + } + }; + + // add callback + listenableFuture.addCallback(new ListenableFutureCallback() { + @Override + public void onSuccess(T result) { + completable.complete(result); + } + + @Override + public void onFailure(Throwable t) { + completable.completeExceptionally(t); + } + }); + return completable; + } + + @Test(expected=NotFoundException.class) + public void confirmAltAppCantUseTestAppResources(){ + + assertThat(rest.get("http://localhost:8080/alternative-app/test-status/ping"),is("test!")); + + } + @Test(expected=NotFoundException.class) + public void confirmTestAppCantUseAltAppResources(){ + + assertThat((List)rest.post("http://localhost:8081/test-app/alt-status/ping",new ImmutableEntity("value",Arrays.asList("hello","world")),List.class), + hasItem("hello")); + + } +} diff --git a/micro-grizzly/src/test/java/app/embedded/com/oath/micro/server/ImmutableEntity.java b/micro-grizzly/src/test/java/app/embedded/com/oath/micro/server/ImmutableEntity.java new file mode 100644 index 000000000..337b63b89 --- /dev/null +++ b/micro-grizzly/src/test/java/app/embedded/com/oath/micro/server/ImmutableEntity.java @@ -0,0 +1,29 @@ +package app.embedded.com.oath.micro.server; + +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Builder; + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "") +@XmlRootElement(name = "immutable") +@Getter +@AllArgsConstructor +@Builder +public class ImmutableEntity { + + private final String value; + private final List list; + + public ImmutableEntity() { + this(null,null); + } + +} diff --git a/micro-grizzly/src/test/java/app/embedded/com/oath/micro/server/TestAppResource.java b/micro-grizzly/src/test/java/app/embedded/com/oath/micro/server/TestAppResource.java new file mode 100644 index 000000000..ebf830d95 --- /dev/null +++ b/micro-grizzly/src/test/java/app/embedded/com/oath/micro/server/TestAppResource.java @@ -0,0 +1,49 @@ +package app.embedded.com.oath.micro.server; + +import java.util.Arrays; +import java.util.List; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import cyclops.async.SimpleReact; +import cyclops.reactive.FutureStream; +import org.springframework.stereotype.Component; + + +import com.oath.micro.server.testing.RestAgent; +@Component +@Path("/test-status") +public class TestAppResource implements TestAppRestResource { + + private final SimpleReact simpleReact = new SimpleReact(); + private final RestAgent template = new RestAgent(); + private final List urls = Arrays.asList("http://localhost:8081/alternative-app/alt-status/ping", + "http://localhost:8080/test-app/test-status/ping", + "http://localhost:8082/simple-app/status/ping", + "http://localhost:8080/test-app/test-status/ping"); + + + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "test!"; + } + + @GET + @Produces("text/plain") + @Path("/rest-calls") + public String restCallResult(){ + + return FutureStream.builder().fromIterable(urls) + .map(it ->template.get(it)) + .then(it -> "*"+it) + .peek(loadedAndModified -> System.out.println(loadedAndModified)) + .block().stream().reduce("", (acc,next) -> acc+"-"+next); + + } + +} diff --git a/micro-grizzly/src/test/java/app/embedded/com/oath/micro/server/TestAppRestResource.java b/micro-grizzly/src/test/java/app/embedded/com/oath/micro/server/TestAppRestResource.java new file mode 100644 index 000000000..7d4df5753 --- /dev/null +++ b/micro-grizzly/src/test/java/app/embedded/com/oath/micro/server/TestAppRestResource.java @@ -0,0 +1,7 @@ +package app.embedded.com.oath.micro.server; + +import com.oath.micro.server.auto.discovery.RestResource; + +public interface TestAppRestResource extends RestResource { + +} diff --git a/micro-grizzly/src/test/java/app/filter/com/aol/micro/server/AutodiscoveredFilter.java b/micro-grizzly/src/test/java/app/filter/com/aol/micro/server/AutodiscoveredFilter.java deleted file mode 100644 index 52a8959db..000000000 --- a/micro-grizzly/src/test/java/app/filter/com/aol/micro/server/AutodiscoveredFilter.java +++ /dev/null @@ -1,70 +0,0 @@ -package app.filter.com.aol.micro.server; - -import java.io.IOException; - -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; - -import cyclops.control.Either; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - - -import com.aol.micro.server.auto.discovery.AutoFilterConfiguration; - -import lombok.Getter; -import lombok.Setter; - -@Component -public class AutodiscoveredFilter implements AutoFilterConfiguration { - - @Autowired - Bean bean; - @Getter - @Setter - private static volatile int called= 0; - - @Getter - private static boolean beanSet = false; - - @Override - public String[] getMapping() { - return new String[] { "/*" }; - } - public Either,Filter> getFilter(){ - - return Either.left(org.springframework.web.filter.DelegatingFilterProxy.class); - - } - public String getName(){ - return "autodiscoveredFilter"; - } - - @Override - public void init(FilterConfig filterConfig) throws ServletException { - - } - - @Override - public void doFilter(ServletRequest request, ServletResponse response, - FilterChain chain) throws IOException, ServletException { - - called++; - if(bean!=null) - beanSet =true; - chain.doFilter(request, response); - } - - @Override - public void destroy() { - - - } - - - -} \ No newline at end of file diff --git a/micro-grizzly/src/test/java/app/filter/com/aol/micro/server/Bean.java b/micro-grizzly/src/test/java/app/filter/com/aol/micro/server/Bean.java deleted file mode 100644 index f95b44b05..000000000 --- a/micro-grizzly/src/test/java/app/filter/com/aol/micro/server/Bean.java +++ /dev/null @@ -1,8 +0,0 @@ -package app.filter.com.aol.micro.server; - -import org.springframework.stereotype.Component; - -@Component -public class Bean { - -} diff --git a/micro-grizzly/src/test/java/app/filter/com/aol/micro/server/ConfiguredFilter.java b/micro-grizzly/src/test/java/app/filter/com/aol/micro/server/ConfiguredFilter.java deleted file mode 100644 index e00bc941b..000000000 --- a/micro-grizzly/src/test/java/app/filter/com/aol/micro/server/ConfiguredFilter.java +++ /dev/null @@ -1,38 +0,0 @@ -package app.filter.com.aol.micro.server; - -import java.io.IOException; - -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; - -import lombok.Getter; - -public class ConfiguredFilter implements Filter { - - @Getter - private static volatile int called= 0; - @Override - public void init(FilterConfig filterConfig) throws ServletException { - // TODO Auto-generated method stub - - } - - @Override - public void doFilter(ServletRequest request, ServletResponse response, - FilterChain chain) throws IOException, ServletException { - called++; - chain.doFilter(request, response); - - } - - @Override - public void destroy() { - // TODO Auto-generated method stub - - } - -} diff --git a/micro-grizzly/src/test/java/app/filter/com/aol/micro/server/FilterAppLocalMain.java b/micro-grizzly/src/test/java/app/filter/com/aol/micro/server/FilterAppLocalMain.java deleted file mode 100644 index 25dc01cc3..000000000 --- a/micro-grizzly/src/test/java/app/filter/com/aol/micro/server/FilterAppLocalMain.java +++ /dev/null @@ -1,22 +0,0 @@ -package app.filter.com.aol.micro.server; - -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; - -import app.servlet.com.aol.micro.server.AppRunnerLocalMain; - -import com.aol.micro.server.MicroserverApp; -@Configuration -@ComponentScan(basePackages = { "app.filter.com.aol.micro.server" }) -public class FilterAppLocalMain { - - - - - public static void main(String[] args) throws InterruptedException { - - new MicroserverApp( FilterAppLocalMain.class, () -> "filter-app") - .run(); - } - - } \ No newline at end of file diff --git a/micro-grizzly/src/test/java/app/filter/com/aol/micro/server/FilterRunnerTest.java b/micro-grizzly/src/test/java/app/filter/com/aol/micro/server/FilterRunnerTest.java deleted file mode 100644 index 239ca7258..000000000 --- a/micro-grizzly/src/test/java/app/filter/com/aol/micro/server/FilterRunnerTest.java +++ /dev/null @@ -1,64 +0,0 @@ -package app.filter.com.aol.micro.server; - - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.Arrays; -import java.util.Map; -import java.util.concurrent.ExecutionException; - -import javax.servlet.Filter; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.testing.RestAgent; -import com.aol.micro.server.utility.HashMapBuilder; - - - -public class FilterRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer(){ - Map filters = HashMapBuilder.map("/filter-app/status/ping2",new ConfiguredFilter()).build(); - server = new MicroserverApp(ConfigurableModule.builder() - .context("filter-app") - .filters(filters ) - .requestListeners(Arrays.asList(new org.springframework.web.context.request.RequestContextListener())).build()); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void testAutoDiscoveredFilter() throws InterruptedException, ExecutionException{ - AutodiscoveredFilter.setCalled(0); - - assertThat(rest.get("http://localhost:8080/filter-app/status/ping"),is("ok")); - assertThat(AutodiscoveredFilter.getCalled(),is(1)); - assertThat(AutodiscoveredFilter.isBeanSet(),is(true)); - } - @Test - public void testConfiguredFilter() throws InterruptedException, ExecutionException{ - - assertThat(ConfiguredFilter.getCalled(),is(0)); - assertThat(rest.get("http://localhost:8080/filter-app/status/ping2"),is("ok")); - assertThat(ConfiguredFilter.getCalled(),is(1)); - } - - - - -} diff --git a/micro-grizzly/src/test/java/app/filter/com/aol/micro/server/FilterStatusResource.java b/micro-grizzly/src/test/java/app/filter/com/aol/micro/server/FilterStatusResource.java deleted file mode 100644 index 2d046711b..000000000 --- a/micro-grizzly/src/test/java/app/filter/com/aol/micro/server/FilterStatusResource.java +++ /dev/null @@ -1,37 +0,0 @@ -package app.filter.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.config.ConfigurableBeanFactory; -import org.springframework.context.annotation.Scope; -import org.springframework.stereotype.Component; -import org.springframework.web.context.WebApplicationContext; - -import com.aol.micro.server.auto.discovery.RestResource; - -@Component -@Scope(value=ConfigurableBeanFactory.SCOPE_PROTOTYPE) -@Path("/status") -public class FilterStatusResource implements RestResource { - - @Autowired - private RequestScopeUserInfo info; - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - info.print(); - return "ok"; - } - @GET - @Produces("text/plain") - @Path("/ping2") - public String ping2() { - return "ok"; - } - -} \ No newline at end of file diff --git a/micro-grizzly/src/test/java/app/filter/com/aol/micro/server/RequestScopeUserInfo.java b/micro-grizzly/src/test/java/app/filter/com/aol/micro/server/RequestScopeUserInfo.java deleted file mode 100644 index c41605c39..000000000 --- a/micro-grizzly/src/test/java/app/filter/com/aol/micro/server/RequestScopeUserInfo.java +++ /dev/null @@ -1,20 +0,0 @@ -package app.filter.com.aol.micro.server; - -import javax.servlet.http.HttpServletRequest; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Scope; -import org.springframework.context.annotation.ScopedProxyMode; -import org.springframework.stereotype.Component; -import org.springframework.web.context.WebApplicationContext; - -@Component -@Scope(value=WebApplicationContext.SCOPE_REQUEST,proxyMode=ScopedProxyMode.TARGET_CLASS) -public class RequestScopeUserInfo { - @Autowired - private HttpServletRequest request; - - public void print(){ - System.out.println(request.getAttribute("oc.info")); - } -} diff --git a/micro-grizzly/src/test/java/app/filter/com/oath/micro/server/AutodiscoveredFilter.java b/micro-grizzly/src/test/java/app/filter/com/oath/micro/server/AutodiscoveredFilter.java new file mode 100644 index 000000000..1f6dfc284 --- /dev/null +++ b/micro-grizzly/src/test/java/app/filter/com/oath/micro/server/AutodiscoveredFilter.java @@ -0,0 +1,70 @@ +package app.filter.com.oath.micro.server; + +import java.io.IOException; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; + +import cyclops.control.Either; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + + +import com.oath.micro.server.auto.discovery.AutoFilterConfiguration; + +import lombok.Getter; +import lombok.Setter; + +@Component +public class AutodiscoveredFilter implements AutoFilterConfiguration { + + @Autowired + Bean bean; + @Getter + @Setter + private static volatile int called= 0; + + @Getter + private static boolean beanSet = false; + + @Override + public String[] getMapping() { + return new String[] { "/*" }; + } + public Either,Filter> getFilter(){ + + return Either.left(org.springframework.web.filter.DelegatingFilterProxy.class); + + } + public String getName(){ + return "autodiscoveredFilter"; + } + + @Override + public void init(FilterConfig filterConfig) throws ServletException { + + } + + @Override + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + called++; + if(bean!=null) + beanSet =true; + chain.doFilter(request, response); + } + + @Override + public void destroy() { + + + } + + + +} \ No newline at end of file diff --git a/micro-grizzly/src/test/java/app/filter/com/oath/micro/server/Bean.java b/micro-grizzly/src/test/java/app/filter/com/oath/micro/server/Bean.java new file mode 100644 index 000000000..e036a796f --- /dev/null +++ b/micro-grizzly/src/test/java/app/filter/com/oath/micro/server/Bean.java @@ -0,0 +1,8 @@ +package app.filter.com.oath.micro.server; + +import org.springframework.stereotype.Component; + +@Component +public class Bean { + +} diff --git a/micro-grizzly/src/test/java/app/filter/com/oath/micro/server/ConfiguredFilter.java b/micro-grizzly/src/test/java/app/filter/com/oath/micro/server/ConfiguredFilter.java new file mode 100644 index 000000000..aca52ad38 --- /dev/null +++ b/micro-grizzly/src/test/java/app/filter/com/oath/micro/server/ConfiguredFilter.java @@ -0,0 +1,38 @@ +package app.filter.com.oath.micro.server; + +import java.io.IOException; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; + +import lombok.Getter; + +public class ConfiguredFilter implements Filter { + + @Getter + private static volatile int called= 0; + @Override + public void init(FilterConfig filterConfig) throws ServletException { + // TODO Auto-generated method stub + + } + + @Override + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + called++; + chain.doFilter(request, response); + + } + + @Override + public void destroy() { + // TODO Auto-generated method stub + + } + +} diff --git a/micro-grizzly/src/test/java/app/filter/com/oath/micro/server/FilterAppLocalMain.java b/micro-grizzly/src/test/java/app/filter/com/oath/micro/server/FilterAppLocalMain.java new file mode 100644 index 000000000..ca4b44b28 --- /dev/null +++ b/micro-grizzly/src/test/java/app/filter/com/oath/micro/server/FilterAppLocalMain.java @@ -0,0 +1,20 @@ +package app.filter.com.oath.micro.server; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +import com.oath.micro.server.MicroserverApp; +@Configuration +@ComponentScan(basePackages = { "app.filter.com.oath.micro.server" }) +public class FilterAppLocalMain { + + + + + public static void main(String[] args) throws InterruptedException { + + new MicroserverApp( FilterAppLocalMain.class, () -> "filter-app") + .run(); + } + + } \ No newline at end of file diff --git a/micro-grizzly/src/test/java/app/filter/com/oath/micro/server/FilterRunnerTest.java b/micro-grizzly/src/test/java/app/filter/com/oath/micro/server/FilterRunnerTest.java new file mode 100644 index 000000000..d3c136b4a --- /dev/null +++ b/micro-grizzly/src/test/java/app/filter/com/oath/micro/server/FilterRunnerTest.java @@ -0,0 +1,64 @@ +package app.filter.com.oath.micro.server; + + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.Arrays; +import java.util.Map; +import java.util.concurrent.ExecutionException; + +import javax.servlet.Filter; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.module.ConfigurableModule; +import com.oath.micro.server.testing.RestAgent; +import com.oath.micro.server.utility.HashMapBuilder; + + + +public class FilterRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer(){ + Map filters = HashMapBuilder.map("/filter-app/status/ping2",new ConfiguredFilter()).build(); + server = new MicroserverApp(ConfigurableModule.builder() + .context("filter-app") + .filters(filters ) + .requestListeners(Arrays.asList(new org.springframework.web.context.request.RequestContextListener())).build()); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void testAutoDiscoveredFilter() throws InterruptedException, ExecutionException{ + AutodiscoveredFilter.setCalled(0); + + assertThat(rest.get("http://localhost:8080/filter-app/status/ping"),is("ok")); + assertThat(AutodiscoveredFilter.getCalled(),is(1)); + assertThat(AutodiscoveredFilter.isBeanSet(),is(true)); + } + @Test + public void testConfiguredFilter() throws InterruptedException, ExecutionException{ + + assertThat(ConfiguredFilter.getCalled(),is(0)); + assertThat(rest.get("http://localhost:8080/filter-app/status/ping2"),is("ok")); + assertThat(ConfiguredFilter.getCalled(),is(1)); + } + + + + +} diff --git a/micro-grizzly/src/test/java/app/filter/com/oath/micro/server/FilterStatusResource.java b/micro-grizzly/src/test/java/app/filter/com/oath/micro/server/FilterStatusResource.java new file mode 100644 index 000000000..c7166c216 --- /dev/null +++ b/micro-grizzly/src/test/java/app/filter/com/oath/micro/server/FilterStatusResource.java @@ -0,0 +1,36 @@ +package app.filter.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.RestResource; + +@Component +@Scope(value=ConfigurableBeanFactory.SCOPE_PROTOTYPE) +@Path("/status") +public class FilterStatusResource implements RestResource { + + @Autowired + private RequestScopeUserInfo info; + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + info.print(); + return "ok"; + } + @GET + @Produces("text/plain") + @Path("/ping2") + public String ping2() { + return "ok"; + } + +} \ No newline at end of file diff --git a/micro-grizzly/src/test/java/app/filter/com/oath/micro/server/RequestScopeUserInfo.java b/micro-grizzly/src/test/java/app/filter/com/oath/micro/server/RequestScopeUserInfo.java new file mode 100644 index 000000000..84c19c3f4 --- /dev/null +++ b/micro-grizzly/src/test/java/app/filter/com/oath/micro/server/RequestScopeUserInfo.java @@ -0,0 +1,20 @@ +package app.filter.com.oath.micro.server; + +import javax.servlet.http.HttpServletRequest; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Scope; +import org.springframework.context.annotation.ScopedProxyMode; +import org.springframework.stereotype.Component; +import org.springframework.web.context.WebApplicationContext; + +@Component +@Scope(value=WebApplicationContext.SCOPE_REQUEST,proxyMode=ScopedProxyMode.TARGET_CLASS) +public class RequestScopeUserInfo { + @Autowired + private HttpServletRequest request; + + public void print(){ + System.out.println(request.getAttribute("oc.info")); + } +} diff --git a/micro-grizzly/src/test/java/app/jackson/custom/com/aol/micro/server/CustomRunnerTest.java b/micro-grizzly/src/test/java/app/jackson/custom/com/aol/micro/server/CustomRunnerTest.java deleted file mode 100644 index 338df9cbc..000000000 --- a/micro-grizzly/src/test/java/app/jackson/custom/com/aol/micro/server/CustomRunnerTest.java +++ /dev/null @@ -1,54 +0,0 @@ -package app.jackson.custom.com.aol.micro.server; - - -import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; - -import java.util.Arrays; -import java.util.concurrent.ExecutionException; - -import org.glassfish.jersey.media.multipart.MultiPartFeature; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.testing.RestAgent; - -@Microserver -public class CustomRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer(){ - server = new MicroserverApp(ConfigurableModule - .builder() - .context("simple-app") - .defaultResources(Arrays.asList(MultiPartFeature.class)) - .build()); - - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - - assertThat(rest.postString("http://localhost:8080/simple-app/status/ping","{\"primitive\":null}").getStatus(),is(500)); - - - } - - - -} diff --git a/micro-grizzly/src/test/java/app/jackson/custom/com/aol/micro/server/CustomStatusResource.java b/micro-grizzly/src/test/java/app/jackson/custom/com/aol/micro/server/CustomStatusResource.java deleted file mode 100644 index d765ba53f..000000000 --- a/micro-grizzly/src/test/java/app/jackson/custom/com/aol/micro/server/CustomStatusResource.java +++ /dev/null @@ -1,20 +0,0 @@ -package app.jackson.custom.com.aol.micro.server; - -import javax.ws.rs.POST; -import javax.ws.rs.Path; - -import com.aol.micro.server.auto.discovery.Rest; - -@Rest -@Path("/status") -public class CustomStatusResource { - - @POST - @Path("/ping") - public String ping(MyEntity entity) { - return "ok"; - - } - - -} \ No newline at end of file diff --git a/micro-grizzly/src/test/java/app/jackson/custom/com/aol/micro/server/MapperExtension.java b/micro-grizzly/src/test/java/app/jackson/custom/com/aol/micro/server/MapperExtension.java deleted file mode 100644 index 3bd1c4e45..000000000 --- a/micro-grizzly/src/test/java/app/jackson/custom/com/aol/micro/server/MapperExtension.java +++ /dev/null @@ -1,18 +0,0 @@ -package app.jackson.custom.com.aol.micro.server; - -import org.springframework.stereotype.Component; - -import com.aol.micro.server.jackson.JacksonMapperConfigurator; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; - -@Component -public class MapperExtension implements JacksonMapperConfigurator { - - @Override - public void accept(ObjectMapper t) { - t.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, true); - - } - -} diff --git a/micro-grizzly/src/test/java/app/jackson/custom/com/aol/micro/server/MyEntity.java b/micro-grizzly/src/test/java/app/jackson/custom/com/aol/micro/server/MyEntity.java deleted file mode 100644 index e62499bff..000000000 --- a/micro-grizzly/src/test/java/app/jackson/custom/com/aol/micro/server/MyEntity.java +++ /dev/null @@ -1,26 +0,0 @@ -package app.jackson.custom.com.aol.micro.server; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -import lombok.Value; - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "") -@XmlRootElement(name = "myentity") -public class MyEntity { - - @XmlElement(name="primitive") - int i; - - public MyEntity(int i) { - super(); - this.i = i; - } - public MyEntity(){ - this.i=-1; - } -} diff --git a/micro-grizzly/src/test/java/app/jackson/custom/com/oath/micro/server/CustomRunnerTest.java b/micro-grizzly/src/test/java/app/jackson/custom/com/oath/micro/server/CustomRunnerTest.java new file mode 100644 index 000000000..93bb107b8 --- /dev/null +++ b/micro-grizzly/src/test/java/app/jackson/custom/com/oath/micro/server/CustomRunnerTest.java @@ -0,0 +1,54 @@ +package app.jackson.custom.com.oath.micro.server; + + +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.assertThat; + +import java.util.Arrays; +import java.util.concurrent.ExecutionException; + +import org.glassfish.jersey.media.multipart.MultiPartFeature; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.module.ConfigurableModule; +import com.oath.micro.server.testing.RestAgent; + +@Microserver +public class CustomRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer(){ + server = new MicroserverApp(ConfigurableModule + .builder() + .context("simple-app") + .defaultResources(Arrays.asList(MultiPartFeature.class)) + .build()); + + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + + assertThat(rest.postString("http://localhost:8080/simple-app/status/ping","{\"primitive\":null}").getStatus(),is(500)); + + + } + + + +} diff --git a/micro-grizzly/src/test/java/app/jackson/custom/com/oath/micro/server/CustomStatusResource.java b/micro-grizzly/src/test/java/app/jackson/custom/com/oath/micro/server/CustomStatusResource.java new file mode 100644 index 000000000..6e8a488ba --- /dev/null +++ b/micro-grizzly/src/test/java/app/jackson/custom/com/oath/micro/server/CustomStatusResource.java @@ -0,0 +1,20 @@ +package app.jackson.custom.com.oath.micro.server; + +import javax.ws.rs.POST; +import javax.ws.rs.Path; + +import com.oath.micro.server.auto.discovery.Rest; + +@Rest +@Path("/status") +public class CustomStatusResource { + + @POST + @Path("/ping") + public String ping(MyEntity entity) { + return "ok"; + + } + + +} \ No newline at end of file diff --git a/micro-grizzly/src/test/java/app/jackson/custom/com/oath/micro/server/MapperExtension.java b/micro-grizzly/src/test/java/app/jackson/custom/com/oath/micro/server/MapperExtension.java new file mode 100644 index 000000000..60a50428a --- /dev/null +++ b/micro-grizzly/src/test/java/app/jackson/custom/com/oath/micro/server/MapperExtension.java @@ -0,0 +1,18 @@ +package app.jackson.custom.com.oath.micro.server; + +import org.springframework.stereotype.Component; + +import com.oath.micro.server.jackson.JacksonMapperConfigurator; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; + +@Component +public class MapperExtension implements JacksonMapperConfigurator { + + @Override + public void accept(ObjectMapper t) { + t.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, true); + + } + +} diff --git a/micro-grizzly/src/test/java/app/jackson/custom/com/oath/micro/server/MyEntity.java b/micro-grizzly/src/test/java/app/jackson/custom/com/oath/micro/server/MyEntity.java new file mode 100644 index 000000000..79f8f0b9a --- /dev/null +++ b/micro-grizzly/src/test/java/app/jackson/custom/com/oath/micro/server/MyEntity.java @@ -0,0 +1,24 @@ +package app.jackson.custom.com.oath.micro.server; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "") +@XmlRootElement(name = "myentity") +public class MyEntity { + + @XmlElement(name="primitive") + int i; + + public MyEntity(int i) { + super(); + this.i = i; + } + public MyEntity(){ + this.i=-1; + } +} diff --git a/micro-grizzly/src/test/java/app/jackson/includes/all/com/aol/micro/server/copy/IncludesRunnerTest.java b/micro-grizzly/src/test/java/app/jackson/includes/all/com/aol/micro/server/copy/IncludesRunnerTest.java deleted file mode 100644 index cb69f2db4..000000000 --- a/micro-grizzly/src/test/java/app/jackson/includes/all/com/aol/micro/server/copy/IncludesRunnerTest.java +++ /dev/null @@ -1,57 +0,0 @@ -package app.jackson.includes.all.com.aol.micro.server.copy; - - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.Arrays; -import java.util.concurrent.ExecutionException; - -import javax.ws.rs.core.Response; - -import org.glassfish.jersey.media.multipart.MultiPartFeature; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.testing.RestAgent; - -@Microserver(properties={"jackson.serialization","ALWAYS"}) -public class IncludesRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer(){ - server = new MicroserverApp(ConfigurableModule - .builder() - .context("simple-app") - .defaultResources(Arrays.asList(MultiPartFeature.class)) - .build()); - - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - - - assertThat(rest.getJson("http://localhost:8080/simple-app/status/ping"),is("{\"primitive\":null}")); - - - } - - - -} diff --git a/micro-grizzly/src/test/java/app/jackson/includes/all/com/aol/micro/server/copy/IncludesStatusResource.java b/micro-grizzly/src/test/java/app/jackson/includes/all/com/aol/micro/server/copy/IncludesStatusResource.java deleted file mode 100644 index 566d503b9..000000000 --- a/micro-grizzly/src/test/java/app/jackson/includes/all/com/aol/micro/server/copy/IncludesStatusResource.java +++ /dev/null @@ -1,22 +0,0 @@ -package app.jackson.includes.all.com.aol.micro.server.copy; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import com.aol.micro.server.auto.discovery.Rest; - -@Rest -@Path("/status") -public class IncludesStatusResource { - - @GET - @Path("/ping") - @Produces("application/json") - public MyEntity ping() { - return new MyEntity(); - - } - - -} \ No newline at end of file diff --git a/micro-grizzly/src/test/java/app/jackson/includes/all/com/aol/micro/server/copy/MyEntity.java b/micro-grizzly/src/test/java/app/jackson/includes/all/com/aol/micro/server/copy/MyEntity.java deleted file mode 100644 index e2c6b02ba..000000000 --- a/micro-grizzly/src/test/java/app/jackson/includes/all/com/aol/micro/server/copy/MyEntity.java +++ /dev/null @@ -1,26 +0,0 @@ -package app.jackson.includes.all.com.aol.micro.server.copy; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -import lombok.Value; - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "") -@XmlRootElement(name = "myentity") -public class MyEntity { - - @XmlElement(name="primitive") - Integer i = null; - - public MyEntity(int i) { - super(); - this.i = i; - } - public MyEntity(){ - this.i=null; - } -} diff --git a/micro-grizzly/src/test/java/app/jackson/includes/all/com/oath/micro/server/copy/IncludesRunnerTest.java b/micro-grizzly/src/test/java/app/jackson/includes/all/com/oath/micro/server/copy/IncludesRunnerTest.java new file mode 100644 index 000000000..59fce660a --- /dev/null +++ b/micro-grizzly/src/test/java/app/jackson/includes/all/com/oath/micro/server/copy/IncludesRunnerTest.java @@ -0,0 +1,55 @@ +package app.jackson.includes.all.com.oath.micro.server.copy; + + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.Arrays; +import java.util.concurrent.ExecutionException; + +import org.glassfish.jersey.media.multipart.MultiPartFeature; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.module.ConfigurableModule; +import com.oath.micro.server.testing.RestAgent; + +@Microserver(properties={"jackson.serialization","ALWAYS"}) +public class IncludesRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer(){ + server = new MicroserverApp(ConfigurableModule + .builder() + .context("simple-app") + .defaultResources(Arrays.asList(MultiPartFeature.class)) + .build()); + + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + + + assertThat(rest.getJson("http://localhost:8080/simple-app/status/ping"),is("{\"primitive\":null}")); + + + } + + + +} diff --git a/micro-grizzly/src/test/java/app/jackson/includes/all/com/oath/micro/server/copy/IncludesStatusResource.java b/micro-grizzly/src/test/java/app/jackson/includes/all/com/oath/micro/server/copy/IncludesStatusResource.java new file mode 100644 index 000000000..bc0d8f3bb --- /dev/null +++ b/micro-grizzly/src/test/java/app/jackson/includes/all/com/oath/micro/server/copy/IncludesStatusResource.java @@ -0,0 +1,22 @@ +package app.jackson.includes.all.com.oath.micro.server.copy; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import com.oath.micro.server.auto.discovery.Rest; + +@Rest +@Path("/status") +public class IncludesStatusResource { + + @GET + @Path("/ping") + @Produces("application/json") + public MyEntity ping() { + return new MyEntity(); + + } + + +} \ No newline at end of file diff --git a/micro-grizzly/src/test/java/app/jackson/includes/all/com/oath/micro/server/copy/MyEntity.java b/micro-grizzly/src/test/java/app/jackson/includes/all/com/oath/micro/server/copy/MyEntity.java new file mode 100644 index 000000000..2b28c5d5b --- /dev/null +++ b/micro-grizzly/src/test/java/app/jackson/includes/all/com/oath/micro/server/copy/MyEntity.java @@ -0,0 +1,24 @@ +package app.jackson.includes.all.com.oath.micro.server.copy; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "") +@XmlRootElement(name = "myentity") +public class MyEntity { + + @XmlElement(name="primitive") + Integer i = null; + + public MyEntity(int i) { + super(); + this.i = i; + } + public MyEntity(){ + this.i=null; + } +} diff --git a/micro-grizzly/src/test/java/app/jackson/includes/nonnull/com/aol/micro/server/IncludesRunnerTest.java b/micro-grizzly/src/test/java/app/jackson/includes/nonnull/com/aol/micro/server/IncludesRunnerTest.java deleted file mode 100644 index ee7b44059..000000000 --- a/micro-grizzly/src/test/java/app/jackson/includes/nonnull/com/aol/micro/server/IncludesRunnerTest.java +++ /dev/null @@ -1,57 +0,0 @@ -package app.jackson.includes.nonnull.com.aol.micro.server; - - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.Arrays; -import java.util.concurrent.ExecutionException; - -import javax.ws.rs.core.Response; - -import org.glassfish.jersey.media.multipart.MultiPartFeature; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.testing.RestAgent; - -@Microserver -public class IncludesRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer(){ - server = new MicroserverApp(ConfigurableModule - .builder() - .context("simple-app") - .defaultResources(Arrays.asList(MultiPartFeature.class)) - .build()); - - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - - - assertThat(rest.getJson("http://localhost:8080/simple-app/status/ping"),is("{}")); - - - } - - - -} diff --git a/micro-grizzly/src/test/java/app/jackson/includes/nonnull/com/aol/micro/server/IncludesStatusResource.java b/micro-grizzly/src/test/java/app/jackson/includes/nonnull/com/aol/micro/server/IncludesStatusResource.java deleted file mode 100644 index f3a9b74b4..000000000 --- a/micro-grizzly/src/test/java/app/jackson/includes/nonnull/com/aol/micro/server/IncludesStatusResource.java +++ /dev/null @@ -1,22 +0,0 @@ -package app.jackson.includes.nonnull.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import com.aol.micro.server.auto.discovery.Rest; - -@Rest -@Path("/status") -public class IncludesStatusResource { - - @GET - @Path("/ping") - @Produces("application/json") - public MyEntity ping() { - return new MyEntity(); - - } - - -} \ No newline at end of file diff --git a/micro-grizzly/src/test/java/app/jackson/includes/nonnull/com/aol/micro/server/MyEntity.java b/micro-grizzly/src/test/java/app/jackson/includes/nonnull/com/aol/micro/server/MyEntity.java deleted file mode 100644 index 3caa39982..000000000 --- a/micro-grizzly/src/test/java/app/jackson/includes/nonnull/com/aol/micro/server/MyEntity.java +++ /dev/null @@ -1,26 +0,0 @@ -package app.jackson.includes.nonnull.com.aol.micro.server; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -import lombok.Value; - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "") -@XmlRootElement(name = "myentity") -public class MyEntity { - - @XmlElement(name="primitive") - Integer i = null; - - public MyEntity(int i) { - super(); - this.i = i; - } - public MyEntity(){ - this.i=null; - } -} diff --git a/micro-grizzly/src/test/java/app/jackson/includes/nonnull/com/oath/micro/server/IncludesRunnerTest.java b/micro-grizzly/src/test/java/app/jackson/includes/nonnull/com/oath/micro/server/IncludesRunnerTest.java new file mode 100644 index 000000000..0171ea10f --- /dev/null +++ b/micro-grizzly/src/test/java/app/jackson/includes/nonnull/com/oath/micro/server/IncludesRunnerTest.java @@ -0,0 +1,55 @@ +package app.jackson.includes.nonnull.com.oath.micro.server; + + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.Arrays; +import java.util.concurrent.ExecutionException; + +import org.glassfish.jersey.media.multipart.MultiPartFeature; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.module.ConfigurableModule; +import com.oath.micro.server.testing.RestAgent; + +@Microserver +public class IncludesRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer(){ + server = new MicroserverApp(ConfigurableModule + .builder() + .context("simple-app") + .defaultResources(Arrays.asList(MultiPartFeature.class)) + .build()); + + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + + + assertThat(rest.getJson("http://localhost:8080/simple-app/status/ping"),is("{}")); + + + } + + + +} diff --git a/micro-grizzly/src/test/java/app/jackson/includes/nonnull/com/oath/micro/server/IncludesStatusResource.java b/micro-grizzly/src/test/java/app/jackson/includes/nonnull/com/oath/micro/server/IncludesStatusResource.java new file mode 100644 index 000000000..477b68744 --- /dev/null +++ b/micro-grizzly/src/test/java/app/jackson/includes/nonnull/com/oath/micro/server/IncludesStatusResource.java @@ -0,0 +1,22 @@ +package app.jackson.includes.nonnull.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import com.oath.micro.server.auto.discovery.Rest; + +@Rest +@Path("/status") +public class IncludesStatusResource { + + @GET + @Path("/ping") + @Produces("application/json") + public MyEntity ping() { + return new MyEntity(); + + } + + +} \ No newline at end of file diff --git a/micro-grizzly/src/test/java/app/jackson/includes/nonnull/com/oath/micro/server/MyEntity.java b/micro-grizzly/src/test/java/app/jackson/includes/nonnull/com/oath/micro/server/MyEntity.java new file mode 100644 index 000000000..6671f20d4 --- /dev/null +++ b/micro-grizzly/src/test/java/app/jackson/includes/nonnull/com/oath/micro/server/MyEntity.java @@ -0,0 +1,24 @@ +package app.jackson.includes.nonnull.com.oath.micro.server; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "") +@XmlRootElement(name = "myentity") +public class MyEntity { + + @XmlElement(name="primitive") + Integer i = null; + + public MyEntity(int i) { + super(); + this.i = i; + } + public MyEntity(){ + this.i=null; + } +} diff --git a/micro-grizzly/src/test/java/app/listeners/com/aol/micro/server/AutodiscoveredListener.java b/micro-grizzly/src/test/java/app/listeners/com/aol/micro/server/AutodiscoveredListener.java deleted file mode 100644 index d20d97709..000000000 --- a/micro-grizzly/src/test/java/app/listeners/com/aol/micro/server/AutodiscoveredListener.java +++ /dev/null @@ -1,31 +0,0 @@ -package app.listeners.com.aol.micro.server; - -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; - -import lombok.Getter; - -import org.springframework.stereotype.Component; - -@Component -public class AutodiscoveredListener implements ServletContextListener { - - @Getter - private static volatile int called= 0; - - @Override - public void contextInitialized(ServletContextEvent sce) { - called ++; - - } - - @Override - public void contextDestroyed(ServletContextEvent sce) { - - - } - - - - -} \ No newline at end of file diff --git a/micro-grizzly/src/test/java/app/listeners/com/aol/micro/server/ConfiguredListener.java b/micro-grizzly/src/test/java/app/listeners/com/aol/micro/server/ConfiguredListener.java deleted file mode 100644 index d15dcb76e..000000000 --- a/micro-grizzly/src/test/java/app/listeners/com/aol/micro/server/ConfiguredListener.java +++ /dev/null @@ -1,25 +0,0 @@ -package app.listeners.com.aol.micro.server; - -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; - -import lombok.Getter; - -public class ConfiguredListener implements ServletContextListener { - - @Getter - private static volatile int called= 0; - - @Override - public void contextInitialized(ServletContextEvent sce) { - called ++; - - } - - @Override - public void contextDestroyed(ServletContextEvent sce) { - - - } - -} \ No newline at end of file diff --git a/micro-grizzly/src/test/java/app/listeners/com/aol/micro/server/ListenerRunnerTest.java b/micro-grizzly/src/test/java/app/listeners/com/aol/micro/server/ListenerRunnerTest.java deleted file mode 100644 index 4f8d7ab69..000000000 --- a/micro-grizzly/src/test/java/app/listeners/com/aol/micro/server/ListenerRunnerTest.java +++ /dev/null @@ -1,55 +0,0 @@ -package app.listeners.com.aol.micro.server; - - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.ExecutionException; - -import javax.servlet.ServletContextListener; - - - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.testing.RestAgent; - - -@Microserver -public class ListenerRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer(){ - List listeners = Arrays.asList(new ConfiguredListener()); - server = new MicroserverApp( ListenerRunnerTest.class, ConfigurableModule.builder().context("listener-app").listeners(listeners ).build()); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void testListeners() throws InterruptedException, ExecutionException{ - - assertThat(AutodiscoveredListener.getCalled(),is(1)); - assertThat(ConfiguredListener.getCalled(),is(1)); - } - - - - - -} diff --git a/micro-grizzly/src/test/java/app/listeners/com/oath/micro/server/AutodiscoveredListener.java b/micro-grizzly/src/test/java/app/listeners/com/oath/micro/server/AutodiscoveredListener.java new file mode 100644 index 000000000..9c7be370e --- /dev/null +++ b/micro-grizzly/src/test/java/app/listeners/com/oath/micro/server/AutodiscoveredListener.java @@ -0,0 +1,31 @@ +package app.listeners.com.oath.micro.server; + +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; + +import lombok.Getter; + +import org.springframework.stereotype.Component; + +@Component +public class AutodiscoveredListener implements ServletContextListener { + + @Getter + private static volatile int called= 0; + + @Override + public void contextInitialized(ServletContextEvent sce) { + called ++; + + } + + @Override + public void contextDestroyed(ServletContextEvent sce) { + + + } + + + + +} \ No newline at end of file diff --git a/micro-grizzly/src/test/java/app/listeners/com/oath/micro/server/ConfiguredListener.java b/micro-grizzly/src/test/java/app/listeners/com/oath/micro/server/ConfiguredListener.java new file mode 100644 index 000000000..86a7cd34b --- /dev/null +++ b/micro-grizzly/src/test/java/app/listeners/com/oath/micro/server/ConfiguredListener.java @@ -0,0 +1,25 @@ +package app.listeners.com.oath.micro.server; + +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; + +import lombok.Getter; + +public class ConfiguredListener implements ServletContextListener { + + @Getter + private static volatile int called= 0; + + @Override + public void contextInitialized(ServletContextEvent sce) { + called ++; + + } + + @Override + public void contextDestroyed(ServletContextEvent sce) { + + + } + +} \ No newline at end of file diff --git a/micro-grizzly/src/test/java/app/listeners/com/oath/micro/server/ListenerRunnerTest.java b/micro-grizzly/src/test/java/app/listeners/com/oath/micro/server/ListenerRunnerTest.java new file mode 100644 index 000000000..fa0222a76 --- /dev/null +++ b/micro-grizzly/src/test/java/app/listeners/com/oath/micro/server/ListenerRunnerTest.java @@ -0,0 +1,55 @@ +package app.listeners.com.oath.micro.server; + + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.ExecutionException; + +import javax.servlet.ServletContextListener; + + + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.module.ConfigurableModule; +import com.oath.micro.server.testing.RestAgent; + + +@Microserver +public class ListenerRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer(){ + List listeners = Arrays.asList(new ConfiguredListener()); + server = new MicroserverApp( ListenerRunnerTest.class, ConfigurableModule.builder().context("listener-app").listeners(listeners ).build()); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void testListeners() throws InterruptedException, ExecutionException{ + + assertThat(AutodiscoveredListener.getCalled(),is(1)); + assertThat(ConfiguredListener.getCalled(),is(1)); + } + + + + + +} diff --git a/micro-grizzly/src/test/java/app/minimal/com/aol/micro/server/MinimalClassTest.java b/micro-grizzly/src/test/java/app/minimal/com/aol/micro/server/MinimalClassTest.java deleted file mode 100644 index 04367ecbd..000000000 --- a/micro-grizzly/src/test/java/app/minimal/com/aol/micro/server/MinimalClassTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package app.minimal.com.aol.micro.server; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.auto.discovery.RestResource; -import com.aol.micro.server.testing.RestAgent; - -@Rest -@Path("/single") -public class MinimalClassTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer(){ - - server = new MicroserverApp(()-> "minimal-app"); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - - - assertThat(rest.get("http://localhost:8080/minimal-app/single/ping"),is("ok")); - - } - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "ok"; - } - - -} \ No newline at end of file diff --git a/micro-grizzly/src/test/java/app/minimal/com/oath/micro/server/MinimalClassTest.java b/micro-grizzly/src/test/java/app/minimal/com/oath/micro/server/MinimalClassTest.java new file mode 100644 index 000000000..c018eb7b2 --- /dev/null +++ b/micro-grizzly/src/test/java/app/minimal/com/oath/micro/server/MinimalClassTest.java @@ -0,0 +1,57 @@ +package app.minimal.com.oath.micro.server; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.auto.discovery.Rest; +import com.oath.micro.server.testing.RestAgent; + +@Rest +@Path("/single") +public class MinimalClassTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer(){ + + server = new MicroserverApp(()-> "minimal-app"); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + + + assertThat(rest.get("http://localhost:8080/minimal-app/single/ping"),is("ok")); + + } + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "ok"; + } + + +} \ No newline at end of file diff --git a/micro-grizzly/src/test/java/app/noanno/com/aol/micro/server/copy/NoAnnoRunnerTest.java b/micro-grizzly/src/test/java/app/noanno/com/aol/micro/server/copy/NoAnnoRunnerTest.java deleted file mode 100644 index bb052650c..000000000 --- a/micro-grizzly/src/test/java/app/noanno/com/aol/micro/server/copy/NoAnnoRunnerTest.java +++ /dev/null @@ -1,48 +0,0 @@ -package app.noanno.com.aol.micro.server.copy; - - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.testing.RestAgent; - - -public class NoAnnoRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer(){ - - server = new MicroserverApp(()-> "simple-app"); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - - - assertThat(rest.get("http://localhost:8080/simple-app/status/ping"),is("ok")); - - - } - - - -} diff --git a/micro-grizzly/src/test/java/app/noanno/com/aol/micro/server/copy/NoAnnoStatusResource.java b/micro-grizzly/src/test/java/app/noanno/com/aol/micro/server/copy/NoAnnoStatusResource.java deleted file mode 100644 index 8a3f5efaa..000000000 --- a/micro-grizzly/src/test/java/app/noanno/com/aol/micro/server/copy/NoAnnoStatusResource.java +++ /dev/null @@ -1,24 +0,0 @@ -package app.noanno.com.aol.micro.server.copy; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import com.aol.micro.server.auto.discovery.Rest; - -@Rest -@Path("/status") -public class NoAnnoStatusResource { - - - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - - return "ok"; - } - - -} \ No newline at end of file diff --git a/micro-grizzly/src/test/java/app/noanno/com/aol/micro/server/copy/SimpleApp.java b/micro-grizzly/src/test/java/app/noanno/com/aol/micro/server/copy/SimpleApp.java deleted file mode 100644 index 5fb7e2ca3..000000000 --- a/micro-grizzly/src/test/java/app/noanno/com/aol/micro/server/copy/SimpleApp.java +++ /dev/null @@ -1,12 +0,0 @@ -package app.noanno.com.aol.micro.server.copy; - -import com.aol.micro.server.MicroserverApp; - -public class SimpleApp { - - public static void main(String[] args){ - new MicroserverApp(()-> "simple-app").run(); - } - - -} diff --git a/micro-grizzly/src/test/java/app/noanno/com/oath/micro/server/copy/NoAnnoRunnerTest.java b/micro-grizzly/src/test/java/app/noanno/com/oath/micro/server/copy/NoAnnoRunnerTest.java new file mode 100644 index 000000000..589bf5144 --- /dev/null +++ b/micro-grizzly/src/test/java/app/noanno/com/oath/micro/server/copy/NoAnnoRunnerTest.java @@ -0,0 +1,47 @@ +package app.noanno.com.oath.micro.server.copy; + + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.testing.RestAgent; + + +public class NoAnnoRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer(){ + + server = new MicroserverApp(()-> "simple-app"); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + + + assertThat(rest.get("http://localhost:8080/simple-app/status/ping"),is("ok")); + + + } + + + +} diff --git a/micro-grizzly/src/test/java/app/noanno/com/oath/micro/server/copy/NoAnnoStatusResource.java b/micro-grizzly/src/test/java/app/noanno/com/oath/micro/server/copy/NoAnnoStatusResource.java new file mode 100644 index 000000000..11a42968e --- /dev/null +++ b/micro-grizzly/src/test/java/app/noanno/com/oath/micro/server/copy/NoAnnoStatusResource.java @@ -0,0 +1,24 @@ +package app.noanno.com.oath.micro.server.copy; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import com.oath.micro.server.auto.discovery.Rest; + +@Rest +@Path("/status") +public class NoAnnoStatusResource { + + + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + + return "ok"; + } + + +} \ No newline at end of file diff --git a/micro-grizzly/src/test/java/app/noanno/com/oath/micro/server/copy/SimpleApp.java b/micro-grizzly/src/test/java/app/noanno/com/oath/micro/server/copy/SimpleApp.java new file mode 100644 index 000000000..646004a31 --- /dev/null +++ b/micro-grizzly/src/test/java/app/noanno/com/oath/micro/server/copy/SimpleApp.java @@ -0,0 +1,12 @@ +package app.noanno.com.oath.micro.server.copy; + +import com.oath.micro.server.MicroserverApp; + +public class SimpleApp { + + public static void main(String[] args){ + new MicroserverApp(()-> "simple-app").run(); + } + + +} diff --git a/micro-grizzly/src/test/java/app/properties/com/aol/micro/server/PropertiesClassTest.java b/micro-grizzly/src/test/java/app/properties/com/aol/micro/server/PropertiesClassTest.java deleted file mode 100644 index 78f037570..000000000 --- a/micro-grizzly/src/test/java/app/properties/com/aol/micro/server/PropertiesClassTest.java +++ /dev/null @@ -1,60 +0,0 @@ -package app.properties.com.aol.micro.server; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.springframework.beans.factory.annotation.Value; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.RestResource; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.testing.RestAgent; - -@Microserver(properties = { "override", "oops" }, propertiesName = "application.properties") -@Path("/single") -public class PropertiesClassTest implements RestResource { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Value("${override}") - String overrideValue; - - @Before - public void startServer() { - - server = new MicroserverApp( - PropertiesClassTest.class, () -> "simple-app"); - server.start(); - - } - - @After - public void stopServer() { - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException { - - assertThat(rest.get("http://localhost:8080/simple-app/single/ping"), is("boo!")); - - } - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return overrideValue; - } - -} \ No newline at end of file diff --git a/micro-grizzly/src/test/java/app/properties/com/oath/micro/server/PropertiesClassTest.java b/micro-grizzly/src/test/java/app/properties/com/oath/micro/server/PropertiesClassTest.java new file mode 100644 index 000000000..166cc5be1 --- /dev/null +++ b/micro-grizzly/src/test/java/app/properties/com/oath/micro/server/PropertiesClassTest.java @@ -0,0 +1,60 @@ +package app.properties.com.oath.micro.server; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Value; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.auto.discovery.RestResource; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.testing.RestAgent; + +@Microserver(properties = { "override", "oops" }, propertiesName = "application.properties") +@Path("/single") +public class PropertiesClassTest implements RestResource { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Value("${override}") + String overrideValue; + + @Before + public void startServer() { + + server = new MicroserverApp( + PropertiesClassTest.class, () -> "simple-app"); + server.start(); + + } + + @After + public void stopServer() { + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException { + + assertThat(rest.get("http://localhost:8080/simple-app/single/ping"), is("boo!")); + + } + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return overrideValue; + } + +} \ No newline at end of file diff --git a/micro-grizzly/src/test/java/app/properties/override/com/aol/micro/server/PropertiesClassTest.java b/micro-grizzly/src/test/java/app/properties/override/com/aol/micro/server/PropertiesClassTest.java deleted file mode 100644 index 7e8761eb3..000000000 --- a/micro-grizzly/src/test/java/app/properties/override/com/aol/micro/server/PropertiesClassTest.java +++ /dev/null @@ -1,62 +0,0 @@ -package app.properties.override.com.aol.micro.server; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.RestResource; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.testing.RestAgent; - -@Microserver(properties = { "simple-app1.port", "8080" }, propertiesName = "application.properties") -@Path("/single") -public class PropertiesClassTest implements RestResource { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - - @Before - public void startServer() { - - System.setProperty("simple-app1.port", "8081"); - try { - server = new MicroserverApp( - PropertiesClassTest.class, () -> "simple-app1"); - server.start(); - - } finally { - System.setProperty("simple-app1.port", "8080"); - } - } - - @After - public void stopServer() { - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException { - - assertThat(rest.get("http://localhost:8081/simple-app1/single/ping"), is("boo!")); - - } - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "boo!"; - } - -} \ No newline at end of file diff --git a/micro-grizzly/src/test/java/app/properties/override/com/oath/micro/server/PropertiesClassTest.java b/micro-grizzly/src/test/java/app/properties/override/com/oath/micro/server/PropertiesClassTest.java new file mode 100644 index 000000000..dbea49437 --- /dev/null +++ b/micro-grizzly/src/test/java/app/properties/override/com/oath/micro/server/PropertiesClassTest.java @@ -0,0 +1,62 @@ +package app.properties.override.com.oath.micro.server; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.auto.discovery.RestResource; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.testing.RestAgent; + +@Microserver(properties = { "simple-app1.port", "8080" }, propertiesName = "application.properties") +@Path("/single") +public class PropertiesClassTest implements RestResource { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + + @Before + public void startServer() { + + System.setProperty("simple-app1.port", "8081"); + try { + server = new MicroserverApp( + PropertiesClassTest.class, () -> "simple-app1"); + server.start(); + + } finally { + System.setProperty("simple-app1.port", "8080"); + } + } + + @After + public void stopServer() { + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException { + + assertThat(rest.get("http://localhost:8081/simple-app1/single/ping"), is("boo!")); + + } + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "boo!"; + } + +} \ No newline at end of file diff --git a/micro-grizzly/src/test/java/app/servlet/com/aol/micro/server/AppRunnerLocalMain.java b/micro-grizzly/src/test/java/app/servlet/com/aol/micro/server/AppRunnerLocalMain.java deleted file mode 100644 index b447491a1..000000000 --- a/micro-grizzly/src/test/java/app/servlet/com/aol/micro/server/AppRunnerLocalMain.java +++ /dev/null @@ -1,20 +0,0 @@ -package app.servlet.com.aol.micro.server; - - -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; - -import com.aol.micro.server.MicroserverApp; - -@Configuration -@ComponentScan(basePackages = { "app.servlet.com.aol.micro.server" }) -public class AppRunnerLocalMain { - - - public static void main(String[] args) throws InterruptedException { - - new MicroserverApp( AppRunnerLocalMain.class, () -> "test-app") - .run(); - } - -} diff --git a/micro-grizzly/src/test/java/app/servlet/com/aol/micro/server/AutodiscoveredServlet.java b/micro-grizzly/src/test/java/app/servlet/com/aol/micro/server/AutodiscoveredServlet.java deleted file mode 100644 index 3e64043bf..000000000 --- a/micro-grizzly/src/test/java/app/servlet/com/aol/micro/server/AutodiscoveredServlet.java +++ /dev/null @@ -1,30 +0,0 @@ -package app.servlet.com.aol.micro.server; - -import java.io.IOException; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.AutoServletConfiguration; - -@Component -public class AutodiscoveredServlet extends HttpServlet implements AutoServletConfiguration { - - @Override - public String[] getMapping() { - return new String[] { "/servlet" }; - } - - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) - throws ServletException, IOException { - - resp.setContentType("text/html"); - resp.getWriter().write("hello world"); - } - -} diff --git a/micro-grizzly/src/test/java/app/servlet/com/aol/micro/server/ConfiguredServlet.java b/micro-grizzly/src/test/java/app/servlet/com/aol/micro/server/ConfiguredServlet.java deleted file mode 100644 index 92577a92e..000000000 --- a/micro-grizzly/src/test/java/app/servlet/com/aol/micro/server/ConfiguredServlet.java +++ /dev/null @@ -1,24 +0,0 @@ -package app.servlet.com.aol.micro.server; - -import java.io.IOException; - -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -public class ConfiguredServlet extends HttpServlet { - - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) - throws ServletException, IOException { - resp.setContentType("text/html"); - resp.getWriter().write("configured servlet"); - } - - - -} diff --git a/micro-grizzly/src/test/java/app/servlet/com/aol/micro/server/ServletRunnerTest.java b/micro-grizzly/src/test/java/app/servlet/com/aol/micro/server/ServletRunnerTest.java deleted file mode 100644 index aa6e20b4f..000000000 --- a/micro-grizzly/src/test/java/app/servlet/com/aol/micro/server/ServletRunnerTest.java +++ /dev/null @@ -1,64 +0,0 @@ -package app.servlet.com.aol.micro.server; - - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.ExecutionException; - -import javax.servlet.Servlet; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.testing.RestAgent; - -public class ServletRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer(){ - Map servlets = new HashMap<>(); - servlets.put("/configured", new ConfiguredServlet()); - server = new MicroserverApp( AppRunnerLocalMain.class, ConfigurableModule.builder().context("test-app").servlets(servlets ).build()); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - assertThat(rest.get("http://localhost:8080/test-app/servlet/ping"),is("ok")); - - } - - @Test - public void autoDiscoveredServletTest() throws InterruptedException, ExecutionException{ - - - assertThat(rest.get("http://localhost:8080/servlet"),is("hello world")); - - } - - @Test - public void configuredServletTest() throws InterruptedException, ExecutionException{ - - - assertThat(rest.get("http://localhost:8080/configured"),is("configured servlet")); - - } - - -} diff --git a/micro-grizzly/src/test/java/app/servlet/com/aol/micro/server/ServletStatusResource.java b/micro-grizzly/src/test/java/app/servlet/com/aol/micro/server/ServletStatusResource.java deleted file mode 100644 index 890a64679..000000000 --- a/micro-grizzly/src/test/java/app/servlet/com/aol/micro/server/ServletStatusResource.java +++ /dev/null @@ -1,22 +0,0 @@ -package app.servlet.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.RestResource; - -@Component -@Path("/servlet") -public class ServletStatusResource implements RestResource { - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "ok"; - } - -} \ No newline at end of file diff --git a/micro-grizzly/src/test/java/app/servlet/com/oath/micro/server/AppRunnerLocalMain.java b/micro-grizzly/src/test/java/app/servlet/com/oath/micro/server/AppRunnerLocalMain.java new file mode 100644 index 000000000..217fc92d4 --- /dev/null +++ b/micro-grizzly/src/test/java/app/servlet/com/oath/micro/server/AppRunnerLocalMain.java @@ -0,0 +1,20 @@ +package app.servlet.com.oath.micro.server; + + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +import com.oath.micro.server.MicroserverApp; + +@Configuration +@ComponentScan(basePackages = { "app.servlet.com.oath.micro.server" }) +public class AppRunnerLocalMain { + + + public static void main(String[] args) throws InterruptedException { + + new MicroserverApp( AppRunnerLocalMain.class, () -> "test-app") + .run(); + } + +} diff --git a/micro-grizzly/src/test/java/app/servlet/com/oath/micro/server/AutodiscoveredServlet.java b/micro-grizzly/src/test/java/app/servlet/com/oath/micro/server/AutodiscoveredServlet.java new file mode 100644 index 000000000..66cbfd59c --- /dev/null +++ b/micro-grizzly/src/test/java/app/servlet/com/oath/micro/server/AutodiscoveredServlet.java @@ -0,0 +1,30 @@ +package app.servlet.com.oath.micro.server; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.AutoServletConfiguration; + +@Component +public class AutodiscoveredServlet extends HttpServlet implements AutoServletConfiguration { + + @Override + public String[] getMapping() { + return new String[] { "/servlet" }; + } + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + + resp.setContentType("text/html"); + resp.getWriter().write("hello world"); + } + +} diff --git a/micro-grizzly/src/test/java/app/servlet/com/oath/micro/server/ConfiguredServlet.java b/micro-grizzly/src/test/java/app/servlet/com/oath/micro/server/ConfiguredServlet.java new file mode 100644 index 000000000..65de82291 --- /dev/null +++ b/micro-grizzly/src/test/java/app/servlet/com/oath/micro/server/ConfiguredServlet.java @@ -0,0 +1,21 @@ +package app.servlet.com.oath.micro.server; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class ConfiguredServlet extends HttpServlet { + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + resp.setContentType("text/html"); + resp.getWriter().write("configured servlet"); + } + + + +} diff --git a/micro-grizzly/src/test/java/app/servlet/com/oath/micro/server/ServletRunnerTest.java b/micro-grizzly/src/test/java/app/servlet/com/oath/micro/server/ServletRunnerTest.java new file mode 100644 index 000000000..39f3896e3 --- /dev/null +++ b/micro-grizzly/src/test/java/app/servlet/com/oath/micro/server/ServletRunnerTest.java @@ -0,0 +1,64 @@ +package app.servlet.com.oath.micro.server; + + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ExecutionException; + +import javax.servlet.Servlet; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.module.ConfigurableModule; +import com.oath.micro.server.testing.RestAgent; + +public class ServletRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer(){ + Map servlets = new HashMap<>(); + servlets.put("/configured", new ConfiguredServlet()); + server = new MicroserverApp( AppRunnerLocalMain.class, ConfigurableModule.builder().context("test-app").servlets(servlets ).build()); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + assertThat(rest.get("http://localhost:8080/test-app/servlet/ping"),is("ok")); + + } + + @Test + public void autoDiscoveredServletTest() throws InterruptedException, ExecutionException{ + + + assertThat(rest.get("http://localhost:8080/servlet"),is("hello world")); + + } + + @Test + public void configuredServletTest() throws InterruptedException, ExecutionException{ + + + assertThat(rest.get("http://localhost:8080/configured"),is("configured servlet")); + + } + + +} diff --git a/micro-grizzly/src/test/java/app/servlet/com/oath/micro/server/ServletStatusResource.java b/micro-grizzly/src/test/java/app/servlet/com/oath/micro/server/ServletStatusResource.java new file mode 100644 index 000000000..6d86eeb84 --- /dev/null +++ b/micro-grizzly/src/test/java/app/servlet/com/oath/micro/server/ServletStatusResource.java @@ -0,0 +1,22 @@ +package app.servlet.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.RestResource; + +@Component +@Path("/servlet") +public class ServletStatusResource implements RestResource { + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "ok"; + } + +} \ No newline at end of file diff --git a/micro-grizzly/src/test/java/app/simple/com/aol/micro/server/SimpleApp.java b/micro-grizzly/src/test/java/app/simple/com/aol/micro/server/SimpleApp.java deleted file mode 100644 index 700a2c778..000000000 --- a/micro-grizzly/src/test/java/app/simple/com/aol/micro/server/SimpleApp.java +++ /dev/null @@ -1,18 +0,0 @@ -package app.simple.com.aol.micro.server; - -import java.util.Arrays; - -import org.glassfish.jersey.media.multipart.MultiPartFeature; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.module.ConfigurableModule; - -public class SimpleApp { - - public static void main(String[] args){ - - new MicroserverApp(()-> "simple-app").run(); - } - - -} diff --git a/micro-grizzly/src/test/java/app/simple/com/aol/micro/server/SimpleRunnerTest.java b/micro-grizzly/src/test/java/app/simple/com/aol/micro/server/SimpleRunnerTest.java deleted file mode 100644 index 6249ef506..000000000 --- a/micro-grizzly/src/test/java/app/simple/com/aol/micro/server/SimpleRunnerTest.java +++ /dev/null @@ -1,55 +0,0 @@ -package app.simple.com.aol.micro.server; - - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.Arrays; -import java.util.concurrent.ExecutionException; - -import org.glassfish.jersey.media.multipart.MultiPartFeature; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.testing.RestAgent; - -@Microserver -public class SimpleRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer(){ - server = new MicroserverApp(ConfigurableModule - .builder() - .context("simple-app") - .defaultResources(Arrays.asList(MultiPartFeature.class)) - .build()); - // server = new MicroserverApp(()-> "simple-app"); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - - - assertThat(rest.get("http://localhost:8080/simple-app/status/ping"),is("ok")); - - - } - - - -} diff --git a/micro-grizzly/src/test/java/app/simple/com/aol/micro/server/SimpleStatusResource.java b/micro-grizzly/src/test/java/app/simple/com/aol/micro/server/SimpleStatusResource.java deleted file mode 100644 index 07b6a5610..000000000 --- a/micro-grizzly/src/test/java/app/simple/com/aol/micro/server/SimpleStatusResource.java +++ /dev/null @@ -1,40 +0,0 @@ -package app.simple.com.aol.micro.server; - -import java.io.InputStream; - -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; - -import org.glassfish.jersey.media.multipart.FormDataContentDisposition; -import org.glassfish.jersey.media.multipart.FormDataParam; - -import com.aol.micro.server.auto.discovery.Rest; - -@Rest -@Path("/status") -public class SimpleStatusResource { - - - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - - return "ok"; - } - - @POST - @Consumes(MediaType.MULTIPART_FORM_DATA) - @Produces(MediaType.TEXT_PLAIN) - @Path("/file") - public String create(@FormDataParam("file") InputStream fileInputStream, - @FormDataParam("file") FormDataContentDisposition contentDispositionHeader) { - - return "done"; - } -} \ No newline at end of file diff --git a/micro-grizzly/src/test/java/app/simple/com/oath/micro/server/SimpleApp.java b/micro-grizzly/src/test/java/app/simple/com/oath/micro/server/SimpleApp.java new file mode 100644 index 000000000..e82a92291 --- /dev/null +++ b/micro-grizzly/src/test/java/app/simple/com/oath/micro/server/SimpleApp.java @@ -0,0 +1,13 @@ +package app.simple.com.oath.micro.server; + +import com.oath.micro.server.MicroserverApp; + +public class SimpleApp { + + public static void main(String[] args){ + + new MicroserverApp(()-> "simple-app").run(); + } + + +} diff --git a/micro-grizzly/src/test/java/app/simple/com/oath/micro/server/SimpleRunnerTest.java b/micro-grizzly/src/test/java/app/simple/com/oath/micro/server/SimpleRunnerTest.java new file mode 100644 index 000000000..ce6dd819a --- /dev/null +++ b/micro-grizzly/src/test/java/app/simple/com/oath/micro/server/SimpleRunnerTest.java @@ -0,0 +1,55 @@ +package app.simple.com.oath.micro.server; + + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.Arrays; +import java.util.concurrent.ExecutionException; + +import org.glassfish.jersey.media.multipart.MultiPartFeature; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.module.ConfigurableModule; +import com.oath.micro.server.testing.RestAgent; + +@Microserver +public class SimpleRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer(){ + server = new MicroserverApp(ConfigurableModule + .builder() + .context("simple-app") + .defaultResources(Arrays.asList(MultiPartFeature.class)) + .build()); + // server = new MicroserverApp(()-> "simple-app"); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + + + assertThat(rest.get("http://localhost:8080/simple-app/status/ping"),is("ok")); + + + } + + + +} diff --git a/micro-grizzly/src/test/java/app/simple/com/oath/micro/server/SimpleStatusResource.java b/micro-grizzly/src/test/java/app/simple/com/oath/micro/server/SimpleStatusResource.java new file mode 100644 index 000000000..7be280bdf --- /dev/null +++ b/micro-grizzly/src/test/java/app/simple/com/oath/micro/server/SimpleStatusResource.java @@ -0,0 +1,40 @@ +package app.simple.com.oath.micro.server; + +import java.io.InputStream; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +import org.glassfish.jersey.media.multipart.FormDataContentDisposition; +import org.glassfish.jersey.media.multipart.FormDataParam; + +import com.oath.micro.server.auto.discovery.Rest; + +@Rest +@Path("/status") +public class SimpleStatusResource { + + + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + + return "ok"; + } + + @POST + @Consumes(MediaType.MULTIPART_FORM_DATA) + @Produces(MediaType.TEXT_PLAIN) + @Path("/file") + public String create(@FormDataParam("file") InputStream fileInputStream, + @FormDataParam("file") FormDataContentDisposition contentDispositionHeader) { + + return "done"; + } +} \ No newline at end of file diff --git a/micro-grizzly/src/test/java/app/single/com/aol/micro/server/SingleClassTest.java b/micro-grizzly/src/test/java/app/single/com/aol/micro/server/SingleClassTest.java deleted file mode 100644 index d7725eed3..000000000 --- a/micro-grizzly/src/test/java/app/single/com/aol/micro/server/SingleClassTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package app.single.com.aol.micro.server; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.RestResource; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.testing.RestAgent; - -@Microserver -@Path("/single") -public class SingleClassTest implements RestResource{ - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer(){ - - server = new MicroserverApp( SingleClassTest.class, ()-> "simple-app"); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - - - assertThat(rest.get("http://localhost:8080/simple-app/single/ping"),is("ok")); - - } - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "ok"; - } - - -} \ No newline at end of file diff --git a/micro-grizzly/src/test/java/app/single/com/oath/micro/server/SingleClassTest.java b/micro-grizzly/src/test/java/app/single/com/oath/micro/server/SingleClassTest.java new file mode 100644 index 000000000..c5a34809d --- /dev/null +++ b/micro-grizzly/src/test/java/app/single/com/oath/micro/server/SingleClassTest.java @@ -0,0 +1,58 @@ +package app.single.com.oath.micro.server; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.auto.discovery.RestResource; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.testing.RestAgent; + +@Microserver +@Path("/single") +public class SingleClassTest implements RestResource{ + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer(){ + + server = new MicroserverApp( SingleClassTest.class, ()-> "simple-app"); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + + + assertThat(rest.get("http://localhost:8080/simple-app/single/ping"),is("ok")); + + } + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "ok"; + } + + +} \ No newline at end of file diff --git a/micro-grizzly/src/test/java/app/single/main/com/aol/micro/server/SingleClassApp.java b/micro-grizzly/src/test/java/app/single/main/com/aol/micro/server/SingleClassApp.java deleted file mode 100644 index aef7a170c..000000000 --- a/micro-grizzly/src/test/java/app/single/main/com/aol/micro/server/SingleClassApp.java +++ /dev/null @@ -1,24 +0,0 @@ -package app.single.main.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.Rest; - -@Rest -@Path("/status") -public class SingleClassApp { - - public static void main(String[] args){ - new MicroserverApp(()-> "simple-app").run(); - } - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "ok"; - } - -} diff --git a/micro-grizzly/src/test/java/app/single/main/com/oath/micro/server/SingleClassApp.java b/micro-grizzly/src/test/java/app/single/main/com/oath/micro/server/SingleClassApp.java new file mode 100644 index 000000000..2d7a71917 --- /dev/null +++ b/micro-grizzly/src/test/java/app/single/main/com/oath/micro/server/SingleClassApp.java @@ -0,0 +1,24 @@ +package app.single.main.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.auto.discovery.Rest; + +@Rest +@Path("/status") +public class SingleClassApp { + + public static void main(String[] args){ + new MicroserverApp(()-> "simple-app").run(); + } + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "ok"; + } + +} diff --git a/micro-grizzly/src/test/java/app/single/serverconfig/com/aol/micro/server/SingleClassTest.java b/micro-grizzly/src/test/java/app/single/serverconfig/com/aol/micro/server/SingleClassTest.java deleted file mode 100644 index af9af9878..000000000 --- a/micro-grizzly/src/test/java/app/single/serverconfig/com/aol/micro/server/SingleClassTest.java +++ /dev/null @@ -1,64 +0,0 @@ -package app.single.serverconfig.com.aol.micro.server; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.*; - -import java.util.concurrent.ExecutionException; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.RestResource; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.testing.RestAgent; - - -@Path("/single") -public class SingleClassTest implements RestResource{ - - RestAgent rest = new RestAgent(); - - boolean called; - MicroserverApp server; - @Before - public void startServer(){ - called = false; - server = new MicroserverApp( ConfigurableModule.builder() - .context("hello") - .serverConfigManager(server->called=true) - .build()); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - - - assertThat(rest.get("http://localhost:8080/hello/single/ping"),is("ok")); - assertTrue(called); - - } - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "ok"; - } - - -} \ No newline at end of file diff --git a/micro-grizzly/src/test/java/app/single/serverconfig/com/oath/micro/server/SingleClassTest.java b/micro-grizzly/src/test/java/app/single/serverconfig/com/oath/micro/server/SingleClassTest.java new file mode 100644 index 000000000..4dbcb9705 --- /dev/null +++ b/micro-grizzly/src/test/java/app/single/serverconfig/com/oath/micro/server/SingleClassTest.java @@ -0,0 +1,63 @@ +package app.single.serverconfig.com.oath.micro.server; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.*; + +import java.util.concurrent.ExecutionException; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.auto.discovery.RestResource; +import com.oath.micro.server.module.ConfigurableModule; +import com.oath.micro.server.testing.RestAgent; + + +@Path("/single") +public class SingleClassTest implements RestResource{ + + RestAgent rest = new RestAgent(); + + boolean called; + MicroserverApp server; + @Before + public void startServer(){ + called = false; + server = new MicroserverApp( ConfigurableModule.builder() + .context("hello") + .serverConfigManager(server->called=true) + .build()); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + + + assertThat(rest.get("http://localhost:8080/hello/single/ping"),is("ok")); + assertTrue(called); + + } + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "ok"; + } + + +} \ No newline at end of file diff --git a/micro-grizzly/src/test/java/app/spring/com/aol/micro/server/MyBean.java b/micro-grizzly/src/test/java/app/spring/com/aol/micro/server/MyBean.java deleted file mode 100644 index 1f7a589ff..000000000 --- a/micro-grizzly/src/test/java/app/spring/com/aol/micro/server/MyBean.java +++ /dev/null @@ -1,12 +0,0 @@ -package app.spring.com.aol.micro.server; - -import javax.inject.Inject; - -import lombok.Getter; - -@Getter -public class MyBean { - - @Inject - private MyDependency injected; -} diff --git a/micro-grizzly/src/test/java/app/spring/com/aol/micro/server/MyDependency.java b/micro-grizzly/src/test/java/app/spring/com/aol/micro/server/MyDependency.java deleted file mode 100644 index 48d89e6c5..000000000 --- a/micro-grizzly/src/test/java/app/spring/com/aol/micro/server/MyDependency.java +++ /dev/null @@ -1,12 +0,0 @@ -package app.spring.com.aol.micro.server; - -import lombok.Getter; - -import org.springframework.stereotype.Component; - -@Component -@Getter -public class MyDependency { - - private String data = "hello world"; -} diff --git a/micro-grizzly/src/test/java/app/spring/com/aol/micro/server/SpringRunnerTest.java b/micro-grizzly/src/test/java/app/spring/com/aol/micro/server/SpringRunnerTest.java deleted file mode 100644 index 1a1765be0..000000000 --- a/micro-grizzly/src/test/java/app/spring/com/aol/micro/server/SpringRunnerTest.java +++ /dev/null @@ -1,54 +0,0 @@ -package app.spring.com.aol.micro.server; - - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.springframework.context.annotation.Bean; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.testing.RestAgent; -/**@Configuration -@ComponentScan(basePackages = { "app.spring.com.aol.micro.server" })**/ -@Microserver -public class SpringRunnerTest { - - RestAgent rest = new RestAgent(); - - @Bean - public MyBean mybean(){ - return new MyBean(); - } - - MicroserverApp server; - @Before - public void startServer(){ - - server = new MicroserverApp( SpringRunnerTest.class, ()-> "spring-app"); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void testAutoWiring() throws InterruptedException, ExecutionException{ - - assertThat(rest.get("http://localhost:8080/spring-app/spring/ping"),is("hello world")); - - } - - - - - -} diff --git a/micro-grizzly/src/test/java/app/spring/com/aol/micro/server/SpringStatusResource.java b/micro-grizzly/src/test/java/app/spring/com/aol/micro/server/SpringStatusResource.java deleted file mode 100644 index 331ac997e..000000000 --- a/micro-grizzly/src/test/java/app/spring/com/aol/micro/server/SpringStatusResource.java +++ /dev/null @@ -1,32 +0,0 @@ -package app.spring.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.RestResource; - -@Component -@Path("/spring") -public class SpringStatusResource implements RestResource { - - @Autowired - private MyBean mybean; - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return mybean.getInjected().getData(); - } - @GET - @Produces("text/plain") - @Path("/ping2") - public String ping2() { - return "ok"; - } - -} \ No newline at end of file diff --git a/micro-grizzly/src/test/java/app/spring/com/oath/micro/server/MyBean.java b/micro-grizzly/src/test/java/app/spring/com/oath/micro/server/MyBean.java new file mode 100644 index 000000000..328b7d185 --- /dev/null +++ b/micro-grizzly/src/test/java/app/spring/com/oath/micro/server/MyBean.java @@ -0,0 +1,12 @@ +package app.spring.com.oath.micro.server; + +import javax.inject.Inject; + +import lombok.Getter; + +@Getter +public class MyBean { + + @Inject + private MyDependency injected; +} diff --git a/micro-grizzly/src/test/java/app/spring/com/oath/micro/server/MyDependency.java b/micro-grizzly/src/test/java/app/spring/com/oath/micro/server/MyDependency.java new file mode 100644 index 000000000..1ca23b15b --- /dev/null +++ b/micro-grizzly/src/test/java/app/spring/com/oath/micro/server/MyDependency.java @@ -0,0 +1,12 @@ +package app.spring.com.oath.micro.server; + +import lombok.Getter; + +import org.springframework.stereotype.Component; + +@Component +@Getter +public class MyDependency { + + private String data = "hello world"; +} diff --git a/micro-grizzly/src/test/java/app/spring/com/oath/micro/server/SpringRunnerTest.java b/micro-grizzly/src/test/java/app/spring/com/oath/micro/server/SpringRunnerTest.java new file mode 100644 index 000000000..56483ff3b --- /dev/null +++ b/micro-grizzly/src/test/java/app/spring/com/oath/micro/server/SpringRunnerTest.java @@ -0,0 +1,54 @@ +package app.spring.com.oath.micro.server; + + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.springframework.context.annotation.Bean; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.testing.RestAgent; +/**@Configuration +@ComponentScan(basePackages = { "app.spring.com.oath.micro.server" })**/ +@Microserver +public class SpringRunnerTest { + + RestAgent rest = new RestAgent(); + + @Bean + public MyBean mybean(){ + return new MyBean(); + } + + MicroserverApp server; + @Before + public void startServer(){ + + server = new MicroserverApp( SpringRunnerTest.class, ()-> "spring-app"); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void testAutoWiring() throws InterruptedException, ExecutionException{ + + assertThat(rest.get("http://localhost:8080/spring-app/spring/ping"),is("hello world")); + + } + + + + + +} diff --git a/micro-grizzly/src/test/java/app/spring/com/oath/micro/server/SpringStatusResource.java b/micro-grizzly/src/test/java/app/spring/com/oath/micro/server/SpringStatusResource.java new file mode 100644 index 000000000..ae0c817de --- /dev/null +++ b/micro-grizzly/src/test/java/app/spring/com/oath/micro/server/SpringStatusResource.java @@ -0,0 +1,32 @@ +package app.spring.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.RestResource; + +@Component +@Path("/spring") +public class SpringStatusResource implements RestResource { + + @Autowired + private MyBean mybean; + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return mybean.getInjected().getData(); + } + @GET + @Produces("text/plain") + @Path("/ping2") + public String ping2() { + return "ok"; + } + +} \ No newline at end of file diff --git a/micro-grizzly/src/test/java/app/validation/com/aol/micro/server/ImmutableEntity.java b/micro-grizzly/src/test/java/app/validation/com/aol/micro/server/ImmutableEntity.java deleted file mode 100644 index 5b454305d..000000000 --- a/micro-grizzly/src/test/java/app/validation/com/aol/micro/server/ImmutableEntity.java +++ /dev/null @@ -1,28 +0,0 @@ -package app.validation.com.aol.micro.server; - - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Builder; - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "") -@XmlRootElement(name = "immutable") -@Getter -@AllArgsConstructor -@Builder -public class ImmutableEntity { - - private final String value; - - - public ImmutableEntity() { - this(null); - } - -} diff --git a/micro-grizzly/src/test/java/app/validation/com/aol/micro/server/ValidationAppResource.java b/micro-grizzly/src/test/java/app/validation/com/aol/micro/server/ValidationAppResource.java deleted file mode 100644 index 880c619e8..000000000 --- a/micro-grizzly/src/test/java/app/validation/com/aol/micro/server/ValidationAppResource.java +++ /dev/null @@ -1,23 +0,0 @@ -package app.validation.com.aol.micro.server; - -import javax.validation.constraints.NotNull; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.RestResource; -@Component -@Path("/status") -public class ValidationAppResource implements RestResource { - - @POST - @Produces("application/json") - @Path("/ping") - public ImmutableEntity ping( @NotNull ImmutableEntity entity) { - return entity; - } - - -} diff --git a/micro-grizzly/src/test/java/app/validation/com/aol/micro/server/ValidationAppTest.java b/micro-grizzly/src/test/java/app/validation/com/aol/micro/server/ValidationAppTest.java deleted file mode 100644 index 8cd76c3de..000000000 --- a/micro-grizzly/src/test/java/app/validation/com/aol/micro/server/ValidationAppTest.java +++ /dev/null @@ -1,71 +0,0 @@ -package app.validation.com.aol.micro.server; - -import java.util.concurrent.ExecutionException; - -import javax.ws.rs.BadRequestException; - -import com.oath.cyclops.types.futurestream.SimpleReactStream; -import cyclops.async.SimpleReact; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.testing.RestAgent; - -//@Microserver(basePackages = { "app.guava.com.aol.micro.server" }) -public class ValidationAppTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - - ImmutableEntity entity; - - - SimpleReact simpleReact = new SimpleReact(); - SimpleReactStream stream; - - @Before - public void startServer() { - stream = simpleReact.ofAsync( - () -> server = new MicroserverApp(() -> "guava-app")).then(server -> server.start()); - - entity = ImmutableEntity.builder().value("value").build(); - - - } - - @After - public void stopServer() { - server.stop(); - } - - - @Test(expected=BadRequestException.class) - public void confirmError() throws InterruptedException, - ExecutionException { - - stream.block(); - rest.post( - "http://localhost:8080/guava-app/status/ping", null, - ImmutableEntity.class); - - - } - @Test - public void confirmNoError() throws InterruptedException, - ExecutionException { - - stream.block(); - rest.post( - "http://localhost:8080/guava-app/status/ping", entity, - ImmutableEntity.class); - - - } - - - -} diff --git a/micro-grizzly/src/test/java/app/validation/com/oath/micro/server/ImmutableEntity.java b/micro-grizzly/src/test/java/app/validation/com/oath/micro/server/ImmutableEntity.java new file mode 100644 index 000000000..19e8f5b26 --- /dev/null +++ b/micro-grizzly/src/test/java/app/validation/com/oath/micro/server/ImmutableEntity.java @@ -0,0 +1,28 @@ +package app.validation.com.oath.micro.server; + + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Builder; + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "") +@XmlRootElement(name = "immutable") +@Getter +@AllArgsConstructor +@Builder +public class ImmutableEntity { + + private final String value; + + + public ImmutableEntity() { + this(null); + } + +} diff --git a/micro-grizzly/src/test/java/app/validation/com/oath/micro/server/ValidationAppResource.java b/micro-grizzly/src/test/java/app/validation/com/oath/micro/server/ValidationAppResource.java new file mode 100644 index 000000000..7a8d0c325 --- /dev/null +++ b/micro-grizzly/src/test/java/app/validation/com/oath/micro/server/ValidationAppResource.java @@ -0,0 +1,23 @@ +package app.validation.com.oath.micro.server; + +import javax.validation.constraints.NotNull; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.RestResource; +@Component +@Path("/status") +public class ValidationAppResource implements RestResource { + + @POST + @Produces("application/json") + @Path("/ping") + public ImmutableEntity ping( @NotNull ImmutableEntity entity) { + return entity; + } + + +} diff --git a/micro-grizzly/src/test/java/app/validation/com/oath/micro/server/ValidationAppTest.java b/micro-grizzly/src/test/java/app/validation/com/oath/micro/server/ValidationAppTest.java new file mode 100644 index 000000000..d209491df --- /dev/null +++ b/micro-grizzly/src/test/java/app/validation/com/oath/micro/server/ValidationAppTest.java @@ -0,0 +1,71 @@ +package app.validation.com.oath.micro.server; + +import java.util.concurrent.ExecutionException; + +import javax.ws.rs.BadRequestException; + +import com.oath.cyclops.types.futurestream.SimpleReactStream; +import cyclops.async.SimpleReact; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.testing.RestAgent; + +//@Microserver(basePackages = { "app.guava.com.oath.micro.server" }) +public class ValidationAppTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + + ImmutableEntity entity; + + + SimpleReact simpleReact = new SimpleReact(); + SimpleReactStream stream; + + @Before + public void startServer() { + stream = simpleReact.ofAsync( + () -> server = new MicroserverApp(() -> "guava-app")).then(server -> server.start()); + + entity = ImmutableEntity.builder().value("value").build(); + + + } + + @After + public void stopServer() { + server.stop(); + } + + + @Test(expected=BadRequestException.class) + public void confirmError() throws InterruptedException, + ExecutionException { + + stream.block(); + rest.post( + "http://localhost:8080/guava-app/status/ping", null, + ImmutableEntity.class); + + + } + @Test + public void confirmNoError() throws InterruptedException, + ExecutionException { + + stream.block(); + rest.post( + "http://localhost:8080/guava-app/status/ping", entity, + ImmutableEntity.class); + + + } + + + +} diff --git a/micro-grizzly/src/test/java/com/aol/micro/server/servers/ServerRunnerTest.java b/micro-grizzly/src/test/java/com/aol/micro/server/servers/ServerRunnerTest.java deleted file mode 100644 index f70d9c89a..000000000 --- a/micro-grizzly/src/test/java/com/aol/micro/server/servers/ServerRunnerTest.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.aol.micro.server.servers; - -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - -import java.util.Arrays; -import java.util.concurrent.CompletableFuture; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mockito; -import org.springframework.context.ApplicationContext; - -import com.aol.micro.server.servers.grizzly.GrizzlyApplication; -import com.aol.micro.server.servers.model.AllData; -import com.aol.micro.server.servers.model.ServerData; - - - -public class ServerRunnerTest { - - private ServerRunner serverRunner; - private GrizzlyApplication serverApplication1; - private GrizzlyApplication serverApplication2; - private ServerData[] registered; - volatile int server1Count =0; - volatile int server2Count =0; - @Before - public void setUp() { - - server1Count =0; - server2Count =0; - - ServerData data1 = new ServerData(8080,Arrays.asList(), Mockito.mock(ApplicationContext.class), "url1", () -> "app-context"); - ServerData data2 = new ServerData(8081, Arrays.asList(), Mockito.mock(ApplicationContext.class), "url2", () -> "test-context"); - - serverApplication1 = new GrizzlyApplication(AllData.builder().serverData(data1).build()){ - @Override - public void run(CompletableFuture start,JaxRsServletConfigurer jaxRsConfigurer, CompletableFuture end) { - server1Count++; - start.complete(true); - - } - }; - serverApplication2 = new GrizzlyApplication(AllData.builder().serverData(data2).build()){ - @Override - public void run(CompletableFuture start,JaxRsServletConfigurer jaxRsConfigurer,CompletableFuture end) { - server2Count++; - start.complete(true); - - } - }; - - serverRunner = new ServerRunner( (array) -> {registered = array; } , - Arrays.asList(serverApplication1, serverApplication2), new CompletableFuture()); - - - } - - @Test - public void testRun() { - serverRunner.run(); - assertThat(server1Count,is(1)); - assertThat(server2Count,is(1)); - } -} diff --git a/micro-grizzly/src/test/java/com/aol/micro/server/testing/RestAgent.java b/micro-grizzly/src/test/java/com/aol/micro/server/testing/RestAgent.java deleted file mode 100644 index 24b169f2e..000000000 --- a/micro-grizzly/src/test/java/com/aol/micro/server/testing/RestAgent.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.aol.micro.server.testing; - -import java.util.List; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.Invocation.Builder; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import com.aol.micro.server.rest.jackson.JacksonUtil; - -public class RestAgent { - - - public String getJson(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.get(String.class); - - } - - public String get(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.TEXT_PLAIN); - - return request.get(String.class); - - } - - public T post(String url, Object payload,Class type) { - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); - } - - public Response postString(String url, String payload) { - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.post(Entity.entity(payload,MediaType.APPLICATION_JSON)); - } - -} diff --git a/micro-grizzly/src/test/java/com/oath/micro/server/servers/ServerRunnerTest.java b/micro-grizzly/src/test/java/com/oath/micro/server/servers/ServerRunnerTest.java new file mode 100644 index 000000000..a082597f2 --- /dev/null +++ b/micro-grizzly/src/test/java/com/oath/micro/server/servers/ServerRunnerTest.java @@ -0,0 +1,66 @@ +package com.oath.micro.server.servers; + +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + +import java.util.Arrays; +import java.util.concurrent.CompletableFuture; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.springframework.context.ApplicationContext; + +import com.oath.micro.server.servers.grizzly.GrizzlyApplication; +import com.oath.micro.server.servers.model.AllData; +import com.oath.micro.server.servers.model.ServerData; + + + +public class ServerRunnerTest { + + private ServerRunner serverRunner; + private GrizzlyApplication serverApplication1; + private GrizzlyApplication serverApplication2; + private ServerData[] registered; + volatile int server1Count =0; + volatile int server2Count =0; + @Before + public void setUp() { + + server1Count =0; + server2Count =0; + + ServerData data1 = new ServerData(8080,Arrays.asList(), Mockito.mock(ApplicationContext.class), "url1", () -> "app-context"); + ServerData data2 = new ServerData(8081, Arrays.asList(), Mockito.mock(ApplicationContext.class), "url2", () -> "test-context"); + + serverApplication1 = new GrizzlyApplication(AllData.builder().serverData(data1).build()){ + @Override + public void run(CompletableFuture start,JaxRsServletConfigurer jaxRsConfigurer, CompletableFuture end) { + server1Count++; + start.complete(true); + + } + }; + serverApplication2 = new GrizzlyApplication(AllData.builder().serverData(data2).build()){ + @Override + public void run(CompletableFuture start,JaxRsServletConfigurer jaxRsConfigurer,CompletableFuture end) { + server2Count++; + start.complete(true); + + } + }; + + serverRunner = new ServerRunner( (array) -> {registered = array; } , + Arrays.asList(serverApplication1, serverApplication2), new CompletableFuture()); + + + } + + @Test + public void testRun() { + serverRunner.run(); + assertThat(server1Count,is(1)); + assertThat(server2Count,is(1)); + } +} diff --git a/micro-grizzly/src/test/java/com/oath/micro/server/testing/RestAgent.java b/micro-grizzly/src/test/java/com/oath/micro/server/testing/RestAgent.java new file mode 100644 index 000000000..7b83464d9 --- /dev/null +++ b/micro-grizzly/src/test/java/com/oath/micro/server/testing/RestAgent.java @@ -0,0 +1,64 @@ +package com.oath.micro.server.testing; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.Invocation.Builder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import com.oath.micro.server.rest.jackson.JacksonUtil; + +public class RestAgent { + + + public String getJson(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.get(String.class); + + } + + public String get(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.TEXT_PLAIN); + + return request.get(String.class); + + } + + public T post(String url, Object payload,Class type) { + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); + } + + public Response postString(String url, String payload) { + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.post(Entity.entity(payload,MediaType.APPLICATION_JSON)); + } + +} diff --git a/micro-guava/src/main/java/com/aol/micro/server/guava/GuavaPlugin.java b/micro-guava/src/main/java/com/oath/micro/server/guava/GuavaPlugin.java similarity index 78% rename from micro-guava/src/main/java/com/aol/micro/server/guava/GuavaPlugin.java rename to micro-guava/src/main/java/com/oath/micro/server/guava/GuavaPlugin.java index 2c3d9b908..f198e1152 100644 --- a/micro-guava/src/main/java/com/aol/micro/server/guava/GuavaPlugin.java +++ b/micro-guava/src/main/java/com/oath/micro/server/guava/GuavaPlugin.java @@ -1,11 +1,10 @@ -package com.aol.micro.server.guava; +package com.oath.micro.server.guava; -import com.aol.micro.server.Plugin; -import com.aol.micro.server.guava.spring.GuavaConfig; +import com.oath.micro.server.Plugin; +import com.oath.micro.server.guava.spring.GuavaConfig; import com.fasterxml.jackson.databind.Module; import com.fasterxml.jackson.datatype.guava.GuavaModule; -import cyclops.collections.immutable.PersistentSetX; import cyclops.collections.mutable.SetX; import java.util.Set; diff --git a/micro-guava/src/main/java/com/aol/micro/server/guava/spring/GuavaConfig.java b/micro-guava/src/main/java/com/oath/micro/server/guava/spring/GuavaConfig.java similarity index 86% rename from micro-guava/src/main/java/com/aol/micro/server/guava/spring/GuavaConfig.java rename to micro-guava/src/main/java/com/oath/micro/server/guava/spring/GuavaConfig.java index 2204b319b..e9bb8d3f6 100644 --- a/micro-guava/src/main/java/com/aol/micro/server/guava/spring/GuavaConfig.java +++ b/micro-guava/src/main/java/com/oath/micro/server/guava/spring/GuavaConfig.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.guava.spring; +package com.oath.micro.server.guava.spring; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/micro-guava/src/main/resources/META-INF/services/com.aol.micro.server.Plugin b/micro-guava/src/main/resources/META-INF/services/com.aol.micro.server.Plugin deleted file mode 100644 index c04494ef6..000000000 --- a/micro-guava/src/main/resources/META-INF/services/com.aol.micro.server.Plugin +++ /dev/null @@ -1 +0,0 @@ -com.aol.micro.server.guava.GuavaPlugin \ No newline at end of file diff --git a/micro-guava/src/main/resources/META-INF/services/com.oath.micro.server.Plugin b/micro-guava/src/main/resources/META-INF/services/com.oath.micro.server.Plugin new file mode 100644 index 000000000..384298c9b --- /dev/null +++ b/micro-guava/src/main/resources/META-INF/services/com.oath.micro.server.Plugin @@ -0,0 +1 @@ +com.oath.micro.server.guava.GuavaPlugin \ No newline at end of file diff --git a/micro-guava/src/test/java/app/embedded/com/aol/micro/server/AltAppResource.java b/micro-guava/src/test/java/app/embedded/com/aol/micro/server/AltAppResource.java deleted file mode 100644 index d4b8eff5c..000000000 --- a/micro-guava/src/test/java/app/embedded/com/aol/micro/server/AltAppResource.java +++ /dev/null @@ -1,23 +0,0 @@ -package app.embedded.com.aol.micro.server; - -import java.util.ArrayList; -import java.util.List; - -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.stereotype.Component; - -@Component -@Path("/alt-status") -public class AltAppResource implements AltAppRestResource { - - @POST - @Produces("application/json") - @Path("/ping") - public List ping(ImmutableEntity entity) { - return entity.getList(); - } - -} diff --git a/micro-guava/src/test/java/app/embedded/com/aol/micro/server/AltAppRestResource.java b/micro-guava/src/test/java/app/embedded/com/aol/micro/server/AltAppRestResource.java deleted file mode 100644 index 8cb2643e3..000000000 --- a/micro-guava/src/test/java/app/embedded/com/aol/micro/server/AltAppRestResource.java +++ /dev/null @@ -1,7 +0,0 @@ -package app.embedded.com.aol.micro.server; - -import com.aol.micro.server.auto.discovery.RestResource; - -public interface AltAppRestResource extends RestResource { - -} diff --git a/micro-guava/src/test/java/app/embedded/com/aol/micro/server/EmbeddedAppLocalMain.java b/micro-guava/src/test/java/app/embedded/com/aol/micro/server/EmbeddedAppLocalMain.java deleted file mode 100644 index bc73c2862..000000000 --- a/micro-guava/src/test/java/app/embedded/com/aol/micro/server/EmbeddedAppLocalMain.java +++ /dev/null @@ -1,24 +0,0 @@ -package app.embedded.com.aol.micro.server; - -import java.util.Arrays; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.module.EmbeddedModule; - -@Microserver(basePackages = { "app.embedded.com.aol.micro.server" }) -public class EmbeddedAppLocalMain { - - - public static void main(String[] args) throws InterruptedException { - - new MicroserverApp( - EmbeddedModule.tagInterfaceModule(Arrays.asList(TestAppRestResource.class),"test-app"), - EmbeddedModule.tagInterfaceModule(Arrays.asList(AltAppRestResource.class),"alternative-app")).start(); - - - - } - - -} diff --git a/micro-guava/src/test/java/app/embedded/com/aol/micro/server/EmbeddedAppTest.java b/micro-guava/src/test/java/app/embedded/com/aol/micro/server/EmbeddedAppTest.java deleted file mode 100644 index bf1d3a7a7..000000000 --- a/micro-guava/src/test/java/app/embedded/com/aol/micro/server/EmbeddedAppTest.java +++ /dev/null @@ -1,103 +0,0 @@ -package app.embedded.com.aol.micro.server; - -import static org.hamcrest.Matchers.hasItem; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; - -import javax.ws.rs.NotFoundException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.springframework.util.concurrent.ListenableFuture; -import org.springframework.util.concurrent.ListenableFutureCallback; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.module.EmbeddedModule; -import com.aol.micro.server.testing.RestAgent; -import com.google.common.collect.ImmutableList; - -public class EmbeddedAppTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - - @Before - public void startServer(){ - server = new MicroserverApp(EmbeddedAppLocalMain.class, - EmbeddedModule.tagInterfaceModule(Arrays.asList(TestAppRestResource.class),"test-app"), - EmbeddedModule.tagInterfaceModule(Arrays.asList(AltAppRestResource.class),"alternative-app")); - server.start(); - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void confirmExpectedUrlsPresentTest() throws InterruptedException, ExecutionException{ - - assertThat(rest.get("http://localhost:8080/test-app/test-status/ping"),is("test!")); - - - assertThat((List)rest.post("http://localhost:8081/alternative-app/alt-status/ping",new ImmutableEntity("value",ImmutableList.of("hello","world")),List.class), - hasItem("hello")); - - } - - - @Test - public void nonBlockingRestClientTest(){ - assertThat(rest.get("http://localhost:8080/test-app/test-status/rest-calls"),is("-*test!-*test!")); - } - - CompletableFuture toCompletableFuture( - final ListenableFuture listenableFuture - ) { - //create an instance of CompletableFuture - CompletableFuture completable = new CompletableFuture() { - @Override - public boolean cancel(boolean mayInterruptIfRunning) { - // propagate cancel to the listenable future - boolean result = listenableFuture.cancel(mayInterruptIfRunning); - super.cancel(mayInterruptIfRunning); - return result; - } - }; - - // add callback - listenableFuture.addCallback(new ListenableFutureCallback() { - @Override - public void onSuccess(T result) { - completable.complete(result); - } - - @Override - public void onFailure(Throwable t) { - completable.completeExceptionally(t); - } - }); - return completable; - } - - @Test(expected=NotFoundException.class) - public void confirmAltAppCantUseTestAppResources(){ - - assertThat(rest.get("http://localhost:8080/alternative-app/test-status/ping"),is("test!")); - - } - @Test(expected=NotFoundException.class) - public void confirmTestAppCantUseAltAppResources(){ - - assertThat((List)rest.post("http://localhost:8081/test-app/alt-status/ping",new ImmutableEntity("value",ImmutableList.of("hello","world")),List.class), - hasItem("hello")); - - } -} diff --git a/micro-guava/src/test/java/app/embedded/com/aol/micro/server/ImmutableEntity.java b/micro-guava/src/test/java/app/embedded/com/aol/micro/server/ImmutableEntity.java deleted file mode 100644 index 6dceb48bf..000000000 --- a/micro-guava/src/test/java/app/embedded/com/aol/micro/server/ImmutableEntity.java +++ /dev/null @@ -1,29 +0,0 @@ -package app.embedded.com.aol.micro.server; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Builder; - -import com.google.common.collect.ImmutableList; - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "") -@XmlRootElement(name = "immutable") -@Getter -@AllArgsConstructor -@Builder -public class ImmutableEntity { - - private final String value; - private final ImmutableList list; - - public ImmutableEntity() { - this(null,null); - } - -} diff --git a/micro-guava/src/test/java/app/embedded/com/aol/micro/server/TestAppResource.java b/micro-guava/src/test/java/app/embedded/com/aol/micro/server/TestAppResource.java deleted file mode 100644 index 129d5e3b7..000000000 --- a/micro-guava/src/test/java/app/embedded/com/aol/micro/server/TestAppResource.java +++ /dev/null @@ -1,47 +0,0 @@ -package app.embedded.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import cyclops.async.SimpleReact; -import cyclops.reactive.FutureStream; -import org.springframework.stereotype.Component; - - -import com.aol.micro.server.testing.RestAgent; -import com.google.common.collect.ImmutableList; -@Component -@Path("/test-status") -public class TestAppResource implements TestAppRestResource { - - private final SimpleReact simpleReact = new SimpleReact(); - private final RestAgent template = new RestAgent(); - private final ImmutableList urls = ImmutableList.of("http://localhost:8081/alternative-app/alt-status/ping", - "http://localhost:8080/test-app/test-status/ping", - "http://localhost:8082/simple-app/status/ping", - "http://localhost:8080/test-app/test-status/ping"); - - - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "test!"; - } - - @GET - @Produces("text/plain") - @Path("/rest-calls") - public String restCallResult(){ - - return FutureStream.builder().fromIterable(urls) - .map(it ->template.get(it)) - .then(it -> "*"+it) - .peek(loadedAndModified -> System.out.println(loadedAndModified)) - .block().stream().reduce("", (acc,next) -> acc+"-"+next); - - } - -} diff --git a/micro-guava/src/test/java/app/embedded/com/aol/micro/server/TestAppRestResource.java b/micro-guava/src/test/java/app/embedded/com/aol/micro/server/TestAppRestResource.java deleted file mode 100644 index 3133fd8cc..000000000 --- a/micro-guava/src/test/java/app/embedded/com/aol/micro/server/TestAppRestResource.java +++ /dev/null @@ -1,7 +0,0 @@ -package app.embedded.com.aol.micro.server; - -import com.aol.micro.server.auto.discovery.RestResource; - -public interface TestAppRestResource extends RestResource { - -} diff --git a/micro-guava/src/test/java/app/embedded/com/oath/micro/server/AltAppResource.java b/micro-guava/src/test/java/app/embedded/com/oath/micro/server/AltAppResource.java new file mode 100644 index 000000000..1835ababe --- /dev/null +++ b/micro-guava/src/test/java/app/embedded/com/oath/micro/server/AltAppResource.java @@ -0,0 +1,22 @@ +package app.embedded.com.oath.micro.server; + +import java.util.List; + +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.stereotype.Component; + +@Component +@Path("/alt-status") +public class AltAppResource implements AltAppRestResource { + + @POST + @Produces("application/json") + @Path("/ping") + public List ping(ImmutableEntity entity) { + return entity.getList(); + } + +} diff --git a/micro-guava/src/test/java/app/embedded/com/oath/micro/server/AltAppRestResource.java b/micro-guava/src/test/java/app/embedded/com/oath/micro/server/AltAppRestResource.java new file mode 100644 index 000000000..7045a4f35 --- /dev/null +++ b/micro-guava/src/test/java/app/embedded/com/oath/micro/server/AltAppRestResource.java @@ -0,0 +1,7 @@ +package app.embedded.com.oath.micro.server; + +import com.oath.micro.server.auto.discovery.RestResource; + +public interface AltAppRestResource extends RestResource { + +} diff --git a/micro-guava/src/test/java/app/embedded/com/oath/micro/server/EmbeddedAppLocalMain.java b/micro-guava/src/test/java/app/embedded/com/oath/micro/server/EmbeddedAppLocalMain.java new file mode 100644 index 000000000..dbb290069 --- /dev/null +++ b/micro-guava/src/test/java/app/embedded/com/oath/micro/server/EmbeddedAppLocalMain.java @@ -0,0 +1,24 @@ +package app.embedded.com.oath.micro.server; + +import java.util.Arrays; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.module.EmbeddedModule; + +@Microserver(basePackages = { "app.embedded.com.oath.micro.server" }) +public class EmbeddedAppLocalMain { + + + public static void main(String[] args) throws InterruptedException { + + new MicroserverApp( + EmbeddedModule.tagInterfaceModule(Arrays.asList(TestAppRestResource.class),"test-app"), + EmbeddedModule.tagInterfaceModule(Arrays.asList(AltAppRestResource.class),"alternative-app")).start(); + + + + } + + +} diff --git a/micro-guava/src/test/java/app/embedded/com/oath/micro/server/EmbeddedAppTest.java b/micro-guava/src/test/java/app/embedded/com/oath/micro/server/EmbeddedAppTest.java new file mode 100644 index 000000000..d0327a39b --- /dev/null +++ b/micro-guava/src/test/java/app/embedded/com/oath/micro/server/EmbeddedAppTest.java @@ -0,0 +1,103 @@ +package app.embedded.com.oath.micro.server; + +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; + +import javax.ws.rs.NotFoundException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.springframework.util.concurrent.ListenableFuture; +import org.springframework.util.concurrent.ListenableFutureCallback; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.module.EmbeddedModule; +import com.oath.micro.server.testing.RestAgent; +import com.google.common.collect.ImmutableList; + +public class EmbeddedAppTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + + @Before + public void startServer(){ + server = new MicroserverApp(EmbeddedAppLocalMain.class, + EmbeddedModule.tagInterfaceModule(Arrays.asList(TestAppRestResource.class),"test-app"), + EmbeddedModule.tagInterfaceModule(Arrays.asList(AltAppRestResource.class),"alternative-app")); + server.start(); + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void confirmExpectedUrlsPresentTest() throws InterruptedException, ExecutionException{ + + assertThat(rest.get("http://localhost:8080/test-app/test-status/ping"),is("test!")); + + + assertThat((List)rest.post("http://localhost:8081/alternative-app/alt-status/ping",new ImmutableEntity("value",ImmutableList.of("hello","world")),List.class), + hasItem("hello")); + + } + + + @Test + public void nonBlockingRestClientTest(){ + assertThat(rest.get("http://localhost:8080/test-app/test-status/rest-calls"),is("-*test!-*test!")); + } + + CompletableFuture toCompletableFuture( + final ListenableFuture listenableFuture + ) { + //create an instance of CompletableFuture + CompletableFuture completable = new CompletableFuture() { + @Override + public boolean cancel(boolean mayInterruptIfRunning) { + // propagate cancel to the listenable future + boolean result = listenableFuture.cancel(mayInterruptIfRunning); + super.cancel(mayInterruptIfRunning); + return result; + } + }; + + // add callback + listenableFuture.addCallback(new ListenableFutureCallback() { + @Override + public void onSuccess(T result) { + completable.complete(result); + } + + @Override + public void onFailure(Throwable t) { + completable.completeExceptionally(t); + } + }); + return completable; + } + + @Test(expected=NotFoundException.class) + public void confirmAltAppCantUseTestAppResources(){ + + assertThat(rest.get("http://localhost:8080/alternative-app/test-status/ping"),is("test!")); + + } + @Test(expected=NotFoundException.class) + public void confirmTestAppCantUseAltAppResources(){ + + assertThat((List)rest.post("http://localhost:8081/test-app/alt-status/ping",new ImmutableEntity("value",ImmutableList.of("hello","world")),List.class), + hasItem("hello")); + + } +} diff --git a/micro-guava/src/test/java/app/embedded/com/oath/micro/server/ImmutableEntity.java b/micro-guava/src/test/java/app/embedded/com/oath/micro/server/ImmutableEntity.java new file mode 100644 index 000000000..3d90d3096 --- /dev/null +++ b/micro-guava/src/test/java/app/embedded/com/oath/micro/server/ImmutableEntity.java @@ -0,0 +1,29 @@ +package app.embedded.com.oath.micro.server; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Builder; + +import com.google.common.collect.ImmutableList; + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "") +@XmlRootElement(name = "immutable") +@Getter +@AllArgsConstructor +@Builder +public class ImmutableEntity { + + private final String value; + private final ImmutableList list; + + public ImmutableEntity() { + this(null,null); + } + +} diff --git a/micro-guava/src/test/java/app/embedded/com/oath/micro/server/TestAppResource.java b/micro-guava/src/test/java/app/embedded/com/oath/micro/server/TestAppResource.java new file mode 100644 index 000000000..9e649de44 --- /dev/null +++ b/micro-guava/src/test/java/app/embedded/com/oath/micro/server/TestAppResource.java @@ -0,0 +1,47 @@ +package app.embedded.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import cyclops.async.SimpleReact; +import cyclops.reactive.FutureStream; +import org.springframework.stereotype.Component; + + +import com.oath.micro.server.testing.RestAgent; +import com.google.common.collect.ImmutableList; +@Component +@Path("/test-status") +public class TestAppResource implements TestAppRestResource { + + private final SimpleReact simpleReact = new SimpleReact(); + private final RestAgent template = new RestAgent(); + private final ImmutableList urls = ImmutableList.of("http://localhost:8081/alternative-app/alt-status/ping", + "http://localhost:8080/test-app/test-status/ping", + "http://localhost:8082/simple-app/status/ping", + "http://localhost:8080/test-app/test-status/ping"); + + + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "test!"; + } + + @GET + @Produces("text/plain") + @Path("/rest-calls") + public String restCallResult(){ + + return FutureStream.builder().fromIterable(urls) + .map(it ->template.get(it)) + .then(it -> "*"+it) + .peek(loadedAndModified -> System.out.println(loadedAndModified)) + .block().stream().reduce("", (acc,next) -> acc+"-"+next); + + } + +} diff --git a/micro-guava/src/test/java/app/embedded/com/oath/micro/server/TestAppRestResource.java b/micro-guava/src/test/java/app/embedded/com/oath/micro/server/TestAppRestResource.java new file mode 100644 index 000000000..7d4df5753 --- /dev/null +++ b/micro-guava/src/test/java/app/embedded/com/oath/micro/server/TestAppRestResource.java @@ -0,0 +1,7 @@ +package app.embedded.com.oath.micro.server; + +import com.oath.micro.server.auto.discovery.RestResource; + +public interface TestAppRestResource extends RestResource { + +} diff --git a/micro-guava/src/test/java/app/guava/com/aol/micro/server/GuavaAppResource.java b/micro-guava/src/test/java/app/guava/com/aol/micro/server/GuavaAppResource.java deleted file mode 100644 index a6cdf2661..000000000 --- a/micro-guava/src/test/java/app/guava/com/aol/micro/server/GuavaAppResource.java +++ /dev/null @@ -1,29 +0,0 @@ -package app.guava.com.aol.micro.server; - -import java.util.Optional; - -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import com.aol.micro.server.auto.discovery.Rest; -import com.google.common.collect.ImmutableList; -@Rest -@Path("/status") -public class GuavaAppResource { - - @POST - @Produces("application/json") - @Path("/ping") - - public ImmutableList ping( ImmutableGuavaEntity entity) { - return entity.getList(); - } - @POST - @Produces("application/json") - @Path("/optional") - public Optional optional(Jdk8Entity entity) { - return entity.getName(); - } - -} diff --git a/micro-guava/src/test/java/app/guava/com/aol/micro/server/GuavaAppTest.java b/micro-guava/src/test/java/app/guava/com/aol/micro/server/GuavaAppTest.java deleted file mode 100644 index 15c4d587d..000000000 --- a/micro-guava/src/test/java/app/guava/com/aol/micro/server/GuavaAppTest.java +++ /dev/null @@ -1,92 +0,0 @@ -package app.guava.com.aol.micro.server; - -import static org.hamcrest.Matchers.hasItem; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - -import java.util.List; -import java.util.Optional; -import java.util.concurrent.ExecutionException; - -import com.oath.cyclops.types.futurestream.SimpleReactStream; -import cyclops.async.SimpleReact; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.rest.jackson.JacksonUtil; -import com.aol.micro.server.testing.RestAgent; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMultimap; -import com.google.common.collect.ImmutableSet; - -@Microserver(basePackages = { "app.guava.com.aol.micro.server" }) -public class GuavaAppTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - - ImmutableGuavaEntity entity; - Jdk8Entity present; - Jdk8Entity absent; - - SimpleReact simpleReact = new SimpleReact(); - SimpleReactStream stream; - - @Before - public void startServer() { - stream = simpleReact.ofAsync( - () -> server = new MicroserverApp(GuavaAppTest.class, - () -> "guava-app")).then(server -> server.start()); - - entity = ImmutableGuavaEntity.builder().value("value") - .list(ImmutableList.of("hello", "world")) - .mapOfSets(ImmutableMap.of("key1", ImmutableSet.of(1, 2, 3))) - .multiMap(ImmutableMultimap.of("1", 2, "1", 2, "2", 4)).build(); - - JacksonUtil.convertFromJson(JacksonUtil.serializeToJson(entity), - ImmutableGuavaEntity.class); - - present = Jdk8Entity.builder().name(Optional.of("test")).build(); - - JacksonUtil.convertFromJson(JacksonUtil.serializeToJson(present), - Optional.class); - absent = Jdk8Entity.builder().name(Optional.empty()).build(); - } - - @After - public void stopServer() { - server.stop(); - } - - @Test - public void confirmExpectedUrlsPresentTest() throws InterruptedException, - ExecutionException { - - stream.block(); - - assertThat((List) rest.post( - "http://localhost:8080/guava-app/status/ping", entity, - List.class), hasItem("hello")); - - } - - @Test - public void confirmOptionalConversionWorking() throws InterruptedException, - ExecutionException { - - stream.block(); - - assertThat(rest.post("http://localhost:8080/guava-app/status/optional", - present, String.class), is("\"test\"")); - - assertThat(rest.post("http://localhost:8080/guava-app/status/optional", - absent, String.class), is("null")); - - } - -} diff --git a/micro-guava/src/test/java/app/guava/com/aol/micro/server/ImmutableGuavaEntity.java b/micro-guava/src/test/java/app/guava/com/aol/micro/server/ImmutableGuavaEntity.java deleted file mode 100644 index 7c6294547..000000000 --- a/micro-guava/src/test/java/app/guava/com/aol/micro/server/ImmutableGuavaEntity.java +++ /dev/null @@ -1,34 +0,0 @@ -package app.guava.com.aol.micro.server; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Builder; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMultimap; -import com.google.common.collect.ImmutableSet; - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "") -@XmlRootElement(name = "immutable") -@Getter -@AllArgsConstructor -@Builder -public class ImmutableGuavaEntity { - - private final String value; - private final ImmutableList list; - private final ImmutableMap mapOfSets; - private final ImmutableMultimap multiMap; - - public ImmutableGuavaEntity() { - this(null,null,null,null); - } - -} diff --git a/micro-guava/src/test/java/app/guava/com/aol/micro/server/Jdk8Entity.java b/micro-guava/src/test/java/app/guava/com/aol/micro/server/Jdk8Entity.java deleted file mode 100644 index 722e5cafb..000000000 --- a/micro-guava/src/test/java/app/guava/com/aol/micro/server/Jdk8Entity.java +++ /dev/null @@ -1,27 +0,0 @@ -package app.guava.com.aol.micro.server; - -import java.util.Optional; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Builder; - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "") -@XmlRootElement(name = "optional") -@Getter -@AllArgsConstructor -@Builder -public class Jdk8Entity { - - private final Optional name; - - public Jdk8Entity(){ - name = Optional.empty(); - } -} diff --git a/micro-guava/src/test/java/app/guava/com/oath/micro/server/GuavaAppResource.java b/micro-guava/src/test/java/app/guava/com/oath/micro/server/GuavaAppResource.java new file mode 100644 index 000000000..8a196aafe --- /dev/null +++ b/micro-guava/src/test/java/app/guava/com/oath/micro/server/GuavaAppResource.java @@ -0,0 +1,29 @@ +package app.guava.com.oath.micro.server; + +import java.util.Optional; + +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import com.oath.micro.server.auto.discovery.Rest; +import com.google.common.collect.ImmutableList; +@Rest +@Path("/status") +public class GuavaAppResource { + + @POST + @Produces("application/json") + @Path("/ping") + + public ImmutableList ping( ImmutableGuavaEntity entity) { + return entity.getList(); + } + @POST + @Produces("application/json") + @Path("/optional") + public Optional optional(Jdk8Entity entity) { + return entity.getName(); + } + +} diff --git a/micro-guava/src/test/java/app/guava/com/oath/micro/server/GuavaAppTest.java b/micro-guava/src/test/java/app/guava/com/oath/micro/server/GuavaAppTest.java new file mode 100644 index 000000000..752433a0f --- /dev/null +++ b/micro-guava/src/test/java/app/guava/com/oath/micro/server/GuavaAppTest.java @@ -0,0 +1,92 @@ +package app.guava.com.oath.micro.server; + +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + +import java.util.List; +import java.util.Optional; +import java.util.concurrent.ExecutionException; + +import com.oath.cyclops.types.futurestream.SimpleReactStream; +import cyclops.async.SimpleReact; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.rest.jackson.JacksonUtil; +import com.oath.micro.server.testing.RestAgent; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableMultimap; +import com.google.common.collect.ImmutableSet; + +@Microserver(basePackages = { "app.guava.com.oath.micro.server" }) +public class GuavaAppTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + + ImmutableGuavaEntity entity; + Jdk8Entity present; + Jdk8Entity absent; + + SimpleReact simpleReact = new SimpleReact(); + SimpleReactStream stream; + + @Before + public void startServer() { + stream = simpleReact.ofAsync( + () -> server = new MicroserverApp(GuavaAppTest.class, + () -> "guava-app")).then(server -> server.start()); + + entity = ImmutableGuavaEntity.builder().value("value") + .list(ImmutableList.of("hello", "world")) + .mapOfSets(ImmutableMap.of("key1", ImmutableSet.of(1, 2, 3))) + .multiMap(ImmutableMultimap.of("1", 2, "1", 2, "2", 4)).build(); + + JacksonUtil.convertFromJson(JacksonUtil.serializeToJson(entity), + ImmutableGuavaEntity.class); + + present = Jdk8Entity.builder().name(Optional.of("test")).build(); + + JacksonUtil.convertFromJson(JacksonUtil.serializeToJson(present), + Optional.class); + absent = Jdk8Entity.builder().name(Optional.empty()).build(); + } + + @After + public void stopServer() { + server.stop(); + } + + @Test + public void confirmExpectedUrlsPresentTest() throws InterruptedException, + ExecutionException { + + stream.block(); + + assertThat((List) rest.post( + "http://localhost:8080/guava-app/status/ping", entity, + List.class), hasItem("hello")); + + } + + @Test + public void confirmOptionalConversionWorking() throws InterruptedException, + ExecutionException { + + stream.block(); + + assertThat(rest.post("http://localhost:8080/guava-app/status/optional", + present, String.class), is("\"test\"")); + + assertThat(rest.post("http://localhost:8080/guava-app/status/optional", + absent, String.class), is("null")); + + } + +} diff --git a/micro-guava/src/test/java/app/guava/com/oath/micro/server/ImmutableGuavaEntity.java b/micro-guava/src/test/java/app/guava/com/oath/micro/server/ImmutableGuavaEntity.java new file mode 100644 index 000000000..e4e706907 --- /dev/null +++ b/micro-guava/src/test/java/app/guava/com/oath/micro/server/ImmutableGuavaEntity.java @@ -0,0 +1,34 @@ +package app.guava.com.oath.micro.server; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Builder; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableMultimap; +import com.google.common.collect.ImmutableSet; + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "") +@XmlRootElement(name = "immutable") +@Getter +@AllArgsConstructor +@Builder +public class ImmutableGuavaEntity { + + private final String value; + private final ImmutableList list; + private final ImmutableMap mapOfSets; + private final ImmutableMultimap multiMap; + + public ImmutableGuavaEntity() { + this(null,null,null,null); + } + +} diff --git a/micro-guava/src/test/java/app/guava/com/oath/micro/server/Jdk8Entity.java b/micro-guava/src/test/java/app/guava/com/oath/micro/server/Jdk8Entity.java new file mode 100644 index 000000000..df2b8662e --- /dev/null +++ b/micro-guava/src/test/java/app/guava/com/oath/micro/server/Jdk8Entity.java @@ -0,0 +1,27 @@ +package app.guava.com.oath.micro.server; + +import java.util.Optional; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Builder; + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "") +@XmlRootElement(name = "optional") +@Getter +@AllArgsConstructor +@Builder +public class Jdk8Entity { + + private final Optional name; + + public Jdk8Entity(){ + name = Optional.empty(); + } +} diff --git a/micro-guava/src/test/java/app/validation/com/aol/micro/server/ValidationAppResource.java b/micro-guava/src/test/java/app/validation/com/aol/micro/server/ValidationAppResource.java deleted file mode 100644 index 70c61fd26..000000000 --- a/micro-guava/src/test/java/app/validation/com/aol/micro/server/ValidationAppResource.java +++ /dev/null @@ -1,25 +0,0 @@ -package app.validation.com.aol.micro.server; - -import javax.validation.constraints.NotNull; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.stereotype.Component; - -import app.guava.com.aol.micro.server.ImmutableGuavaEntity; - -import com.aol.micro.server.auto.discovery.RestResource; -@Component -@Path("/status") -public class ValidationAppResource implements RestResource { - - @POST - @Produces("application/json") - @Path("/ping") - public ImmutableGuavaEntity ping( @NotNull ImmutableGuavaEntity entity) { - return entity; - } - - -} diff --git a/micro-guava/src/test/java/app/validation/com/aol/micro/server/ValidationAppTest.java b/micro-guava/src/test/java/app/validation/com/aol/micro/server/ValidationAppTest.java deleted file mode 100644 index 390c8366c..000000000 --- a/micro-guava/src/test/java/app/validation/com/aol/micro/server/ValidationAppTest.java +++ /dev/null @@ -1,82 +0,0 @@ -package app.validation.com.aol.micro.server; - -import java.util.List; -import java.util.concurrent.ExecutionException; - -import javax.ws.rs.InternalServerErrorException; - -import com.oath.cyclops.types.futurestream.SimpleReactStream; -import cyclops.async.SimpleReact; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import app.guava.com.aol.micro.server.ImmutableGuavaEntity; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.testing.RestAgent; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMultimap; -import com.google.common.collect.ImmutableSet; - -@Microserver(basePackages = { "app.guava.com.aol.micro.server" }) -public class ValidationAppTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - - ImmutableGuavaEntity entity; - - - SimpleReact simpleReact = new SimpleReact(); - SimpleReactStream stream; - - @Before - public void startServer() { - stream = simpleReact.ofAsync( - () -> server = new MicroserverApp(ValidationAppTest.class, - () -> "guava-app")).then(server -> server.start()); - - entity = ImmutableGuavaEntity.builder().value("value") - .list(ImmutableList.of("hello", "world")) - .mapOfSets(ImmutableMap.of("key1", ImmutableSet.of(1, 2, 3))) - .multiMap(ImmutableMultimap.of("1", 2, "1", 2, "2", 4)).build(); - - - } - - @After - public void stopServer() { - server.stop(); - } - - - @Test(expected=InternalServerErrorException.class) - public void confirmError() throws InterruptedException, - ExecutionException { - - stream.block(); - rest.post( - "http://localhost:8080/guava-app/status/ping", null, - List.class); - - - } - @Test - public void confirmNoError() throws InterruptedException, - ExecutionException { - - stream.block(); - rest.post( - "http://localhost:8080/guava-app/status/ping", entity, - List.class); - - - } - - - -} diff --git a/micro-guava/src/test/java/app/validation/com/oath/micro/server/ValidationAppResource.java b/micro-guava/src/test/java/app/validation/com/oath/micro/server/ValidationAppResource.java new file mode 100644 index 000000000..a4a665c82 --- /dev/null +++ b/micro-guava/src/test/java/app/validation/com/oath/micro/server/ValidationAppResource.java @@ -0,0 +1,25 @@ +package app.validation.com.oath.micro.server; + +import javax.validation.constraints.NotNull; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.stereotype.Component; + +import app.guava.com.oath.micro.server.ImmutableGuavaEntity; + +import com.oath.micro.server.auto.discovery.RestResource; +@Component +@Path("/status") +public class ValidationAppResource implements RestResource { + + @POST + @Produces("application/json") + @Path("/ping") + public ImmutableGuavaEntity ping( @NotNull ImmutableGuavaEntity entity) { + return entity; + } + + +} diff --git a/micro-guava/src/test/java/app/validation/com/oath/micro/server/ValidationAppTest.java b/micro-guava/src/test/java/app/validation/com/oath/micro/server/ValidationAppTest.java new file mode 100644 index 000000000..57f03bf96 --- /dev/null +++ b/micro-guava/src/test/java/app/validation/com/oath/micro/server/ValidationAppTest.java @@ -0,0 +1,82 @@ +package app.validation.com.oath.micro.server; + +import java.util.List; +import java.util.concurrent.ExecutionException; + +import javax.ws.rs.InternalServerErrorException; + +import com.oath.cyclops.types.futurestream.SimpleReactStream; +import cyclops.async.SimpleReact; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import app.guava.com.oath.micro.server.ImmutableGuavaEntity; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.testing.RestAgent; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableMultimap; +import com.google.common.collect.ImmutableSet; + +@Microserver(basePackages = { "app.guava.com.oath.micro.server" }) +public class ValidationAppTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + + ImmutableGuavaEntity entity; + + + SimpleReact simpleReact = new SimpleReact(); + SimpleReactStream stream; + + @Before + public void startServer() { + stream = simpleReact.ofAsync( + () -> server = new MicroserverApp(ValidationAppTest.class, + () -> "guava-app")).then(server -> server.start()); + + entity = ImmutableGuavaEntity.builder().value("value") + .list(ImmutableList.of("hello", "world")) + .mapOfSets(ImmutableMap.of("key1", ImmutableSet.of(1, 2, 3))) + .multiMap(ImmutableMultimap.of("1", 2, "1", 2, "2", 4)).build(); + + + } + + @After + public void stopServer() { + server.stop(); + } + + + @Test(expected=InternalServerErrorException.class) + public void confirmError() throws InterruptedException, + ExecutionException { + + stream.block(); + rest.post( + "http://localhost:8080/guava-app/status/ping", null, + List.class); + + + } + @Test + public void confirmNoError() throws InterruptedException, + ExecutionException { + + stream.block(); + rest.post( + "http://localhost:8080/guava-app/status/ping", entity, + List.class); + + + } + + + +} diff --git a/micro-guava/src/test/java/com/aol/micro/server/rest/JacksonUtilTest.java b/micro-guava/src/test/java/com/aol/micro/server/rest/JacksonUtilTest.java deleted file mode 100644 index ecf8ee13e..000000000 --- a/micro-guava/src/test/java/com/aol/micro/server/rest/JacksonUtilTest.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.aol.micro.server.rest; - - -import static junit.framework.Assert.assertTrue; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - -import java.util.ArrayList; -import java.util.List; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -import lombok.Getter; -import lombok.Setter; - -import org.junit.Test; - -import com.aol.micro.server.rest.jackson.JacksonUtil; -import com.google.common.collect.ImmutableList; - - -public class JacksonUtilTest { - - @Test - public void testGenerics(){ - String s = JacksonUtil.serializeToJson(ImmutableList.of(new MyEntity())); - ImmutableList list = JacksonUtil.convertFromJson(s, JacksonUtil.getMapper().getTypeFactory().constructParametricType(ImmutableList.class,MyEntity.class)); - assertThat(list.get(0),is(new MyEntity())); - - } - @Test - public void generateSampleRequest() { - - DummyQueryRequest request = new DummyQueryRequest(); - request.getData().add("blah"); - - assertTrue(JacksonUtil.serializeToJson(request).contains("strData")); - - } - - - @Test - public void serialiseAndDeserialise(){ - DummyQueryRequest request = new DummyQueryRequest(); - request.getData().add("blah"); - String requestStr = (String) JacksonUtil.serializeToJsonLogFailure(request); - DummyQueryRequest requestDeserialised = JacksonUtil.convertFromJson(requestStr, DummyQueryRequest.class); - assertTrue(request.getData().contains("blah")); - } - - -} - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlRootElement(name = "queryRequest") -@XmlType(name = "") -class DummyQueryRequest { - - @XmlElement(name = "strData") - @Getter - @Setter - private List data = new ArrayList(); - - -} - diff --git a/micro-guava/src/test/java/com/aol/micro/server/rest/MyEntity.java b/micro-guava/src/test/java/com/aol/micro/server/rest/MyEntity.java deleted file mode 100644 index b6a7a0ec7..000000000 --- a/micro-guava/src/test/java/com/aol/micro/server/rest/MyEntity.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.aol.micro.server.rest; - -import lombok.EqualsAndHashCode; -import lombok.Getter; - -@EqualsAndHashCode -@Getter -public class MyEntity { - - private final String name ="myEntity"; - -} diff --git a/micro-guava/src/test/java/com/aol/micro/server/rest/RestContextListenerTest.java b/micro-guava/src/test/java/com/aol/micro/server/rest/RestContextListenerTest.java deleted file mode 100644 index b853d9a62..000000000 --- a/micro-guava/src/test/java/com/aol/micro/server/rest/RestContextListenerTest.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.aol.micro.server.rest; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.rest.jersey.JerseyRestApplication; -import com.aol.micro.server.rest.jersey.JerseySpringIntegrationContextListener; -import com.aol.micro.server.servers.model.ServerData; -import com.google.common.collect.Lists; - -public class RestContextListenerTest { - - private JerseySpringIntegrationContextListener restContextListener; - private ServletStatusResource statsResource; - - @Before - public void setUp() { - statsResource = new ServletStatusResource(); - ServerData serverData = new ServerData(8080, Lists.newArrayList(statsResource), null, "baseUrl", () -> "test"); - restContextListener = new JerseySpringIntegrationContextListener(serverData); - } - - @Test - public void testContextInitialized() { - restContextListener.contextInitialized(null); - assertThat(JerseyRestApplication.getResourcesMap().get("test").get(0), is(statsResource)); - } - - @Test - public void testContextDestroyed() { - restContextListener.contextDestroyed(null); - } - -} diff --git a/micro-guava/src/test/java/com/aol/micro/server/rest/ServletStatusResource.java b/micro-guava/src/test/java/com/aol/micro/server/rest/ServletStatusResource.java deleted file mode 100644 index c5e3cf667..000000000 --- a/micro-guava/src/test/java/com/aol/micro/server/rest/ServletStatusResource.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.aol.micro.server.rest; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.RestResource; - -@Component -@Path("/servlet") -public class ServletStatusResource implements RestResource { - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "ok"; - } - -} \ No newline at end of file diff --git a/micro-guava/src/test/java/com/aol/micro/server/testing/RestAgent.java b/micro-guava/src/test/java/com/aol/micro/server/testing/RestAgent.java deleted file mode 100644 index ce204f810..000000000 --- a/micro-guava/src/test/java/com/aol/micro/server/testing/RestAgent.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.aol.micro.server.testing; - -import java.util.List; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.Invocation.Builder; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; - -import com.aol.micro.server.rest.jackson.JacksonUtil; - -public class RestAgent { - - - public String getJson(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.get(String.class); - - } - - public String get(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.TEXT_PLAIN); - - return request.get(String.class); - - } - - public T post(String url, Object payload,Class type) { - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); - } - - -} diff --git a/micro-guava/src/test/java/com/oath/micro/server/rest/JacksonUtilTest.java b/micro-guava/src/test/java/com/oath/micro/server/rest/JacksonUtilTest.java new file mode 100644 index 000000000..dde6aebb4 --- /dev/null +++ b/micro-guava/src/test/java/com/oath/micro/server/rest/JacksonUtilTest.java @@ -0,0 +1,70 @@ +package com.oath.micro.server.rest; + + +import static junit.framework.Assert.assertTrue; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +import lombok.Getter; +import lombok.Setter; + +import org.junit.Test; + +import com.oath.micro.server.rest.jackson.JacksonUtil; +import com.google.common.collect.ImmutableList; + + +public class JacksonUtilTest { + + @Test + public void testGenerics(){ + String s = JacksonUtil.serializeToJson(ImmutableList.of(new MyEntity())); + ImmutableList list = JacksonUtil.convertFromJson(s, JacksonUtil.getMapper().getTypeFactory().constructParametricType(ImmutableList.class,MyEntity.class)); + assertThat(list.get(0),is(new MyEntity())); + + } + @Test + public void generateSampleRequest() { + + DummyQueryRequest request = new DummyQueryRequest(); + request.getData().add("blah"); + + assertTrue(JacksonUtil.serializeToJson(request).contains("strData")); + + } + + + @Test + public void serialiseAndDeserialise(){ + DummyQueryRequest request = new DummyQueryRequest(); + request.getData().add("blah"); + String requestStr = (String) JacksonUtil.serializeToJsonLogFailure(request); + DummyQueryRequest requestDeserialised = JacksonUtil.convertFromJson(requestStr, DummyQueryRequest.class); + assertTrue(request.getData().contains("blah")); + } + + +} + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlRootElement(name = "queryRequest") +@XmlType(name = "") +class DummyQueryRequest { + + @XmlElement(name = "strData") + @Getter + @Setter + private List data = new ArrayList(); + + +} + diff --git a/micro-guava/src/test/java/com/oath/micro/server/rest/MyEntity.java b/micro-guava/src/test/java/com/oath/micro/server/rest/MyEntity.java new file mode 100644 index 000000000..c691212ff --- /dev/null +++ b/micro-guava/src/test/java/com/oath/micro/server/rest/MyEntity.java @@ -0,0 +1,12 @@ +package com.oath.micro.server.rest; + +import lombok.EqualsAndHashCode; +import lombok.Getter; + +@EqualsAndHashCode +@Getter +public class MyEntity { + + private final String name ="myEntity"; + +} diff --git a/micro-guava/src/test/java/com/oath/micro/server/rest/RestContextListenerTest.java b/micro-guava/src/test/java/com/oath/micro/server/rest/RestContextListenerTest.java new file mode 100644 index 000000000..715793b5f --- /dev/null +++ b/micro-guava/src/test/java/com/oath/micro/server/rest/RestContextListenerTest.java @@ -0,0 +1,37 @@ +package com.oath.micro.server.rest; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.rest.jersey.JerseyRestApplication; +import com.oath.micro.server.rest.jersey.JerseySpringIntegrationContextListener; +import com.oath.micro.server.servers.model.ServerData; +import com.google.common.collect.Lists; + +public class RestContextListenerTest { + + private JerseySpringIntegrationContextListener restContextListener; + private ServletStatusResource statsResource; + + @Before + public void setUp() { + statsResource = new ServletStatusResource(); + ServerData serverData = new ServerData(8080, Lists.newArrayList(statsResource), null, "baseUrl", () -> "test"); + restContextListener = new JerseySpringIntegrationContextListener(serverData); + } + + @Test + public void testContextInitialized() { + restContextListener.contextInitialized(null); + assertThat(JerseyRestApplication.getResourcesMap().get("test").get(0), is(statsResource)); + } + + @Test + public void testContextDestroyed() { + restContextListener.contextDestroyed(null); + } + +} diff --git a/micro-guava/src/test/java/com/oath/micro/server/rest/ServletStatusResource.java b/micro-guava/src/test/java/com/oath/micro/server/rest/ServletStatusResource.java new file mode 100644 index 000000000..e7fa33979 --- /dev/null +++ b/micro-guava/src/test/java/com/oath/micro/server/rest/ServletStatusResource.java @@ -0,0 +1,22 @@ +package com.oath.micro.server.rest; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.RestResource; + +@Component +@Path("/servlet") +public class ServletStatusResource implements RestResource { + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "ok"; + } + +} \ No newline at end of file diff --git a/micro-guava/src/test/java/com/oath/micro/server/testing/RestAgent.java b/micro-guava/src/test/java/com/oath/micro/server/testing/RestAgent.java new file mode 100644 index 000000000..b2b86303e --- /dev/null +++ b/micro-guava/src/test/java/com/oath/micro/server/testing/RestAgent.java @@ -0,0 +1,53 @@ +package com.oath.micro.server.testing; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.Invocation.Builder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; + +import com.oath.micro.server.rest.jackson.JacksonUtil; + +public class RestAgent { + + + public String getJson(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.get(String.class); + + } + + public String get(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.TEXT_PLAIN); + + return request.get(String.class); + + } + + public T post(String url, Object payload,Class type) { + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); + } + + +} diff --git a/micro-hibernate/src/main/java/com/aol/micro/server/spring/HibernatePlugin.java b/micro-hibernate/src/main/java/com/aol/micro/server/spring/HibernatePlugin.java deleted file mode 100644 index 4cb87d236..000000000 --- a/micro-hibernate/src/main/java/com/aol/micro/server/spring/HibernatePlugin.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.aol.micro.server.spring; - -import java.util.Optional; -import java.util.Set; - - -import com.aol.micro.server.Plugin; -import com.aol.micro.server.spring.datasource.JdbcConfig; -import com.aol.micro.server.spring.datasource.hibernate.HibernateConfig; -import com.aol.micro.server.spring.datasource.hibernate.SpringDataConfig; -import com.aol.micro.server.spring.datasource.jdbc.SQL; -import cyclops.collections.immutable.PersistentSetX; -import cyclops.collections.mutable.SetX; - -/** - * - * Collections of Spring configuration classes (Classes annotated with @Configuration) - * that configure various useful pieces of functionality - such as property file loading, - * datasources, scheduling etc - * - * @author johnmcclean - * - */ -public class HibernatePlugin implements Plugin { - - @Override - public Optional springDbConfigurer() { - return Optional.of(new HibernateSpringConfigurer()); - } - - @Override - public Set springClasses() { - return SetX.of(JdbcConfig.class, SQL.class, SpringDataConfig.class, HibernateConfig.class); - } - - - -} diff --git a/micro-hibernate/src/main/java/com/oath/micro/server/spring/HibernatePlugin.java b/micro-hibernate/src/main/java/com/oath/micro/server/spring/HibernatePlugin.java new file mode 100644 index 000000000..1668f5277 --- /dev/null +++ b/micro-hibernate/src/main/java/com/oath/micro/server/spring/HibernatePlugin.java @@ -0,0 +1,37 @@ +package com.oath.micro.server.spring; + +import java.util.Optional; +import java.util.Set; + + +import com.oath.micro.server.Plugin; +import com.oath.micro.server.spring.datasource.JdbcConfig; +import com.oath.micro.server.spring.datasource.hibernate.HibernateConfig; +import com.oath.micro.server.spring.datasource.hibernate.SpringDataConfig; +import com.oath.micro.server.spring.datasource.jdbc.SQL; +import cyclops.collections.mutable.SetX; + +/** + * + * Collections of Spring configuration classes (Classes annotated with @Configuration) + * that configure various useful pieces of functionality - such as property file loading, + * datasources, scheduling etc + * + * @author johnmcclean + * + */ +public class HibernatePlugin implements Plugin { + + @Override + public Optional springDbConfigurer() { + return Optional.of(new HibernateSpringConfigurer()); + } + + @Override + public Set springClasses() { + return SetX.of(JdbcConfig.class, SQL.class, SpringDataConfig.class, HibernateConfig.class); + } + + + +} diff --git a/micro-hibernate/src/main/java/com/aol/micro/server/spring/HibernateSpringConfigurer.java b/micro-hibernate/src/main/java/com/oath/micro/server/spring/HibernateSpringConfigurer.java similarity index 90% rename from micro-hibernate/src/main/java/com/aol/micro/server/spring/HibernateSpringConfigurer.java rename to micro-hibernate/src/main/java/com/oath/micro/server/spring/HibernateSpringConfigurer.java index 1bbe56833..0fa9a5eda 100644 --- a/micro-hibernate/src/main/java/com/aol/micro/server/spring/HibernateSpringConfigurer.java +++ b/micro-hibernate/src/main/java/com/oath/micro/server/spring/HibernateSpringConfigurer.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.spring; +package com.oath.micro.server.spring; import java.util.Arrays; import java.util.Properties; @@ -12,9 +12,9 @@ import org.springframework.orm.hibernate5.HibernateTransactionManager; import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; -import com.aol.micro.server.config.Config; -import com.aol.micro.server.spring.datasource.JdbcConfig; -import com.aol.micro.server.spring.datasource.hibernate.HibernateSessionBuilder; +import com.oath.micro.server.config.Config; +import com.oath.micro.server.spring.datasource.JdbcConfig; +import com.oath.micro.server.spring.datasource.hibernate.HibernateSessionBuilder; public class HibernateSpringConfigurer implements SpringDBConfig { diff --git a/micro-hibernate/src/main/java/com/aol/micro/server/spring/datasource/hibernate/HibernateConfig.java b/micro-hibernate/src/main/java/com/oath/micro/server/spring/datasource/hibernate/HibernateConfig.java similarity index 87% rename from micro-hibernate/src/main/java/com/aol/micro/server/spring/datasource/hibernate/HibernateConfig.java rename to micro-hibernate/src/main/java/com/oath/micro/server/spring/datasource/hibernate/HibernateConfig.java index f1e7c4392..300d94721 100644 --- a/micro-hibernate/src/main/java/com/aol/micro/server/spring/datasource/hibernate/HibernateConfig.java +++ b/micro-hibernate/src/main/java/com/oath/micro/server/spring/datasource/hibernate/HibernateConfig.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.spring.datasource.hibernate; +package com.oath.micro.server.spring.datasource.hibernate; import javax.annotation.Resource; import javax.sql.DataSource; @@ -9,8 +9,8 @@ import org.springframework.orm.hibernate5.HibernateTransactionManager; import org.springframework.transaction.annotation.EnableTransactionManagement; -import com.aol.micro.server.config.ConfigAccessor; -import com.aol.micro.server.spring.datasource.JdbcConfig; +import com.oath.micro.server.config.ConfigAccessor; +import com.oath.micro.server.spring.datasource.JdbcConfig; import java.util.Arrays; diff --git a/micro-hibernate/src/main/java/com/aol/micro/server/spring/datasource/hibernate/HibernateSessionBuilder.java b/micro-hibernate/src/main/java/com/oath/micro/server/spring/datasource/hibernate/HibernateSessionBuilder.java similarity index 94% rename from micro-hibernate/src/main/java/com/aol/micro/server/spring/datasource/hibernate/HibernateSessionBuilder.java rename to micro-hibernate/src/main/java/com/oath/micro/server/spring/datasource/hibernate/HibernateSessionBuilder.java index 9bfb2dec0..96ad3c1ec 100644 --- a/micro-hibernate/src/main/java/com/aol/micro/server/spring/datasource/hibernate/HibernateSessionBuilder.java +++ b/micro-hibernate/src/main/java/com/oath/micro/server/spring/datasource/hibernate/HibernateSessionBuilder.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.spring.datasource.hibernate; +package com.oath.micro.server.spring.datasource.hibernate; import java.util.List; import java.util.Properties; @@ -15,7 +15,7 @@ import org.springframework.orm.hibernate5.HibernateTransactionManager; import org.springframework.orm.hibernate5.LocalSessionFactoryBean; -import com.aol.micro.server.spring.datasource.JdbcConfig; +import com.oath.micro.server.spring.datasource.JdbcConfig; @Builder @AllArgsConstructor diff --git a/micro-hibernate/src/main/java/com/aol/micro/server/spring/datasource/hibernate/SpringDataConfig.java b/micro-hibernate/src/main/java/com/oath/micro/server/spring/datasource/hibernate/SpringDataConfig.java similarity index 91% rename from micro-hibernate/src/main/java/com/aol/micro/server/spring/datasource/hibernate/SpringDataConfig.java rename to micro-hibernate/src/main/java/com/oath/micro/server/spring/datasource/hibernate/SpringDataConfig.java index 0ed1f1188..8a9eeffd4 100644 --- a/micro-hibernate/src/main/java/com/aol/micro/server/spring/datasource/hibernate/SpringDataConfig.java +++ b/micro-hibernate/src/main/java/com/oath/micro/server/spring/datasource/hibernate/SpringDataConfig.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.spring.datasource.hibernate; +package com.oath.micro.server.spring.datasource.hibernate; import javax.annotation.Resource; import javax.persistence.EntityManagerFactory; @@ -12,8 +12,8 @@ import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.annotation.EnableTransactionManagement; -import com.aol.micro.server.config.ConfigAccessor; -import com.aol.micro.server.spring.datasource.JdbcConfig; +import com.oath.micro.server.config.ConfigAccessor; +import com.oath.micro.server.spring.datasource.JdbcConfig; import java.util.Arrays; diff --git a/micro-hibernate/src/main/resources/META-INF/services/com.aol.micro.server.Plugin b/micro-hibernate/src/main/resources/META-INF/services/com.aol.micro.server.Plugin deleted file mode 100644 index 0159c36a2..000000000 --- a/micro-hibernate/src/main/resources/META-INF/services/com.aol.micro.server.Plugin +++ /dev/null @@ -1 +0,0 @@ -com.aol.micro.server.spring.HibernatePlugin \ No newline at end of file diff --git a/micro-hibernate/src/main/resources/META-INF/services/com.oath.micro.server.Plugin b/micro-hibernate/src/main/resources/META-INF/services/com.oath.micro.server.Plugin new file mode 100644 index 000000000..b4bd5461a --- /dev/null +++ b/micro-hibernate/src/main/resources/META-INF/services/com.oath.micro.server.Plugin @@ -0,0 +1 @@ +com.oath.micro.server.spring.HibernatePlugin \ No newline at end of file diff --git a/micro-hibernate/src/test/java/app/hibernate/com/aol/micro/server/PersistentResource.java b/micro-hibernate/src/test/java/app/hibernate/com/aol/micro/server/PersistentResource.java deleted file mode 100644 index f7b282a55..000000000 --- a/micro-hibernate/src/test/java/app/hibernate/com/aol/micro/server/PersistentResource.java +++ /dev/null @@ -1,60 +0,0 @@ -package app.hibernate.com.aol.micro.server; - -import java.util.List; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.hibernate.Criteria; -import org.hibernate.Session; -import org.hibernate.SessionFactory; -import org.hibernate.criterion.Example; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.RestResource; - -@Component -@Path("/persistence") -public class PersistentResource implements RestResource { - - - private final SessionFactory sessionFactory; - - - @Autowired - public PersistentResource(SessionFactory sessionFactory) { - - this.sessionFactory = sessionFactory; - } - - @GET - @Produces("text/plain") - @Path("/create") - public String createEntity() { - - final Session session = sessionFactory.openSession(); - session.save(HibernateEntity.builder() - .name("test") - .value("value").build()); - session.flush(); - return "ok"; - } - @GET - @Produces("application/json") - @Path("/get") - public List get(){ - final Session session = sessionFactory.openSession(); - - Criteria criteria = session.createCriteria(HibernateEntity.class) - .add(Example.create(HibernateEntity.builder() - .name("test") - .build())); - - return criteria.list(); - - } - - -} \ No newline at end of file diff --git a/micro-hibernate/src/test/java/app/hibernate/com/aol/micro/server/HibernateEntity.java b/micro-hibernate/src/test/java/app/hibernate/com/oath/micro/server/HibernateEntity.java similarity index 96% rename from micro-hibernate/src/test/java/app/hibernate/com/aol/micro/server/HibernateEntity.java rename to micro-hibernate/src/test/java/app/hibernate/com/oath/micro/server/HibernateEntity.java index c25e1c7f8..d4e127d74 100644 --- a/micro-hibernate/src/test/java/app/hibernate/com/aol/micro/server/HibernateEntity.java +++ b/micro-hibernate/src/test/java/app/hibernate/com/oath/micro/server/HibernateEntity.java @@ -1,4 +1,4 @@ -package app.hibernate.com.aol.micro.server; +package app.hibernate.com.oath.micro.server; import static javax.persistence.GenerationType.IDENTITY; diff --git a/micro-hibernate/src/test/java/app/hibernate/com/aol/micro/server/HibernateRunnerTest.java b/micro-hibernate/src/test/java/app/hibernate/com/oath/micro/server/HibernateRunnerTest.java similarity index 77% rename from micro-hibernate/src/test/java/app/hibernate/com/aol/micro/server/HibernateRunnerTest.java rename to micro-hibernate/src/test/java/app/hibernate/com/oath/micro/server/HibernateRunnerTest.java index f42c86847..bba71e3d0 100644 --- a/micro-hibernate/src/test/java/app/hibernate/com/aol/micro/server/HibernateRunnerTest.java +++ b/micro-hibernate/src/test/java/app/hibernate/com/oath/micro/server/HibernateRunnerTest.java @@ -1,4 +1,4 @@ -package app.hibernate.com.aol.micro.server; +package app.hibernate.com.oath.micro.server; import static org.hamcrest.CoreMatchers.is; @@ -11,12 +11,12 @@ import org.junit.Before; import org.junit.Test; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.rest.client.nio.AsyncRestClient; -import com.aol.micro.server.testing.RestAgent; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.rest.client.nio.AsyncRestClient; +import com.oath.micro.server.testing.RestAgent; -@Microserver(entityScan="app.hibernate.com.aol.micro.server",properties={"db.connection.driver","org.hsqldb.jdbcDriver", +@Microserver(entityScan="app.hibernate.com.oath.micro.server",properties={"db.connection.driver","org.hsqldb.jdbcDriver", "db.connection.url","jdbc:hsqldb:mem:aname", "db.connection.username", "sa", "db.connection.dialect","org.hibernate.dialect.HSQLDialect", diff --git a/micro-hibernate/src/test/java/app/hibernate/com/oath/micro/server/PersistentResource.java b/micro-hibernate/src/test/java/app/hibernate/com/oath/micro/server/PersistentResource.java new file mode 100644 index 000000000..dea0c687e --- /dev/null +++ b/micro-hibernate/src/test/java/app/hibernate/com/oath/micro/server/PersistentResource.java @@ -0,0 +1,60 @@ +package app.hibernate.com.oath.micro.server; + +import java.util.List; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.criterion.Example; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.RestResource; + +@Component +@Path("/persistence") +public class PersistentResource implements RestResource { + + + private final SessionFactory sessionFactory; + + + @Autowired + public PersistentResource(SessionFactory sessionFactory) { + + this.sessionFactory = sessionFactory; + } + + @GET + @Produces("text/plain") + @Path("/create") + public String createEntity() { + + final Session session = sessionFactory.openSession(); + session.save(HibernateEntity.builder() + .name("test") + .value("value").build()); + session.flush(); + return "ok"; + } + @GET + @Produces("application/json") + @Path("/get") + public List get(){ + final Session session = sessionFactory.openSession(); + + Criteria criteria = session.createCriteria(HibernateEntity.class) + .add(Example.create(HibernateEntity.builder() + .name("test") + .build())); + + return criteria.list(); + + } + + +} \ No newline at end of file diff --git a/micro-hibernate/src/test/java/app/jdbc/com/aol/micro/server/JdbcRunnerTest.java b/micro-hibernate/src/test/java/app/jdbc/com/aol/micro/server/JdbcRunnerTest.java index 32e160a96..951c02d6d 100644 --- a/micro-hibernate/src/test/java/app/jdbc/com/aol/micro/server/JdbcRunnerTest.java +++ b/micro-hibernate/src/test/java/app/jdbc/com/aol/micro/server/JdbcRunnerTest.java @@ -10,10 +10,10 @@ import org.junit.Before; import org.junit.Test; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.rest.client.nio.AsyncRestClient; -import com.aol.micro.server.testing.RestAgent; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.rest.client.nio.AsyncRestClient; +import com.oath.micro.server.testing.RestAgent; @Microserver(entityScan="app.jdbc.com.aol.micro.server",properties={"db.connection.driver","org.hsqldb.jdbcDriver", "db.connection.url","jdbc:hsqldb:mem:aname", diff --git a/micro-hibernate/src/test/java/app/jdbc/com/aol/micro/server/PersistentResource.java b/micro-hibernate/src/test/java/app/jdbc/com/aol/micro/server/PersistentResource.java index 66c560794..9c405d78c 100644 --- a/micro-hibernate/src/test/java/app/jdbc/com/aol/micro/server/PersistentResource.java +++ b/micro-hibernate/src/test/java/app/jdbc/com/aol/micro/server/PersistentResource.java @@ -7,8 +7,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.BeanPropertyRowMapper; -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.spring.datasource.jdbc.SQL; +import com.oath.micro.server.auto.discovery.Rest; +import com.oath.micro.server.spring.datasource.jdbc.SQL; @Rest @Path("/persistence") diff --git a/micro-hibernate/src/test/java/app/pure/jdbc/com/aol/micro/server/JdbcEntity.java b/micro-hibernate/src/test/java/app/pure/jdbc/com/aol/micro/server/JdbcEntity.java deleted file mode 100644 index 2cc20b3df..000000000 --- a/micro-hibernate/src/test/java/app/pure/jdbc/com/aol/micro/server/JdbcEntity.java +++ /dev/null @@ -1,27 +0,0 @@ -package app.pure.jdbc.com.aol.micro.server; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.Builder; - - - - -@Setter -@Getter -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class JdbcEntity implements java.io.Serializable { - - private static final long serialVersionUID = 1L; - - private Long id; - private String name; - private String value; - private int version; - - -} diff --git a/micro-hibernate/src/test/java/app/pure/jdbc/com/aol/micro/server/JdbcRunnerTest.java b/micro-hibernate/src/test/java/app/pure/jdbc/com/aol/micro/server/JdbcRunnerTest.java deleted file mode 100644 index 612b9d9dd..000000000 --- a/micro-hibernate/src/test/java/app/pure/jdbc/com/aol/micro/server/JdbcRunnerTest.java +++ /dev/null @@ -1,55 +0,0 @@ -package app.pure.jdbc.com.aol.micro.server; - - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.rest.client.nio.AsyncRestClient; -import com.aol.micro.server.testing.RestAgent; - -@Microserver(properties={"db.connection.driver","org.hsqldb.jdbcDriver", - "db.connection.url","jdbc:hsqldb:mem:aname", - "db.connection.username", "sa", - }) -public class JdbcRunnerTest { - - private final AsyncRestClient listClient = new AsyncRestClient(1000,1000).withResponse(JdbcEntity.class); - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - - @Before - public void startServer(){ - - - server = new MicroserverApp(()->"jdbc-app"); - server.start(); - rest.get("http://localhost:8080/jdbc-app/persistence/gen"); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - assertThat(rest.get("http://localhost:8080/jdbc-app/persistence/create"),is("ok")); - assertThat(listClient.get("http://localhost:8080/jdbc-app/persistence/get").get(),is(JdbcEntity.class)); - - } - - - -} diff --git a/micro-hibernate/src/test/java/app/pure/jdbc/com/aol/micro/server/PersistentResource.java b/micro-hibernate/src/test/java/app/pure/jdbc/com/aol/micro/server/PersistentResource.java deleted file mode 100644 index d6e7a8a82..000000000 --- a/micro-hibernate/src/test/java/app/pure/jdbc/com/aol/micro/server/PersistentResource.java +++ /dev/null @@ -1,50 +0,0 @@ -package app.pure.jdbc.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.BeanPropertyRowMapper; - -import app.pure.jdbc.com.aol.micro.server.JdbcEntity; - -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.spring.datasource.jdbc.SQL; - -@Rest -@Path("/persistence") -public class PersistentResource { - - private final SQL dao; - - @Autowired - public PersistentResource(SQL dao) { - - this.dao = dao; - } - @GET - @Produces("text/plain") - @Path("/gen") - public String gen() { - dao.getJdbc().execute("create table t_jdbc(id bigint,name varchar(255),value varchar(255),version int);"); - - return "ok"; - } - @GET - @Produces("text/plain") - @Path("/create") - public String createEntity() { - dao.getJdbc().update("insert into t_jdbc VALUES (1,'hello','world',1)"); - - return "ok"; - } - - @GET - @Produces("application/json") - @Path("/get") - public JdbcEntity get() { - return dao.getJdbc(). queryForObject("select * from t_jdbc", new BeanPropertyRowMapper(JdbcEntity.class)); - } - -} \ No newline at end of file diff --git a/micro-hibernate/src/test/java/app/pure/jdbc/com/oath/micro/server/JdbcEntity.java b/micro-hibernate/src/test/java/app/pure/jdbc/com/oath/micro/server/JdbcEntity.java new file mode 100644 index 000000000..c92fd662b --- /dev/null +++ b/micro-hibernate/src/test/java/app/pure/jdbc/com/oath/micro/server/JdbcEntity.java @@ -0,0 +1,27 @@ +package app.pure.jdbc.com.oath.micro.server; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.Builder; + + + + +@Setter +@Getter +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class JdbcEntity implements java.io.Serializable { + + private static final long serialVersionUID = 1L; + + private Long id; + private String name; + private String value; + private int version; + + +} diff --git a/micro-hibernate/src/test/java/app/pure/jdbc/com/oath/micro/server/JdbcRunnerTest.java b/micro-hibernate/src/test/java/app/pure/jdbc/com/oath/micro/server/JdbcRunnerTest.java new file mode 100644 index 000000000..fe8483a12 --- /dev/null +++ b/micro-hibernate/src/test/java/app/pure/jdbc/com/oath/micro/server/JdbcRunnerTest.java @@ -0,0 +1,55 @@ +package app.pure.jdbc.com.oath.micro.server; + + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.rest.client.nio.AsyncRestClient; +import com.oath.micro.server.testing.RestAgent; + +@Microserver(properties={"db.connection.driver","org.hsqldb.jdbcDriver", + "db.connection.url","jdbc:hsqldb:mem:aname", + "db.connection.username", "sa", + }) +public class JdbcRunnerTest { + + private final AsyncRestClient listClient = new AsyncRestClient(1000,1000).withResponse(JdbcEntity.class); + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + + @Before + public void startServer(){ + + + server = new MicroserverApp(()->"jdbc-app"); + server.start(); + rest.get("http://localhost:8080/jdbc-app/persistence/gen"); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + assertThat(rest.get("http://localhost:8080/jdbc-app/persistence/create"),is("ok")); + assertThat(listClient.get("http://localhost:8080/jdbc-app/persistence/get").get(),is(JdbcEntity.class)); + + } + + + +} diff --git a/micro-hibernate/src/test/java/app/pure/jdbc/com/oath/micro/server/PersistentResource.java b/micro-hibernate/src/test/java/app/pure/jdbc/com/oath/micro/server/PersistentResource.java new file mode 100644 index 000000000..869898590 --- /dev/null +++ b/micro-hibernate/src/test/java/app/pure/jdbc/com/oath/micro/server/PersistentResource.java @@ -0,0 +1,48 @@ +package app.pure.jdbc.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.BeanPropertyRowMapper; + +import com.oath.micro.server.auto.discovery.Rest; +import com.oath.micro.server.spring.datasource.jdbc.SQL; + +@Rest +@Path("/persistence") +public class PersistentResource { + + private final SQL dao; + + @Autowired + public PersistentResource(SQL dao) { + + this.dao = dao; + } + @GET + @Produces("text/plain") + @Path("/gen") + public String gen() { + dao.getJdbc().execute("create table t_jdbc(id bigint,name varchar(255),value varchar(255),version int);"); + + return "ok"; + } + @GET + @Produces("text/plain") + @Path("/create") + public String createEntity() { + dao.getJdbc().update("insert into t_jdbc VALUES (1,'hello','world',1)"); + + return "ok"; + } + + @GET + @Produces("application/json") + @Path("/get") + public JdbcEntity get() { + return dao.getJdbc(). queryForObject("select * from t_jdbc", new BeanPropertyRowMapper(JdbcEntity.class)); + } + +} \ No newline at end of file diff --git a/micro-hibernate/src/test/java/app/spring/data/jpa/com/aol/micro/server/PersistentResource.java b/micro-hibernate/src/test/java/app/spring/data/jpa/com/aol/micro/server/PersistentResource.java deleted file mode 100644 index 62101e2f6..000000000 --- a/micro-hibernate/src/test/java/app/spring/data/jpa/com/aol/micro/server/PersistentResource.java +++ /dev/null @@ -1,46 +0,0 @@ -package app.spring.data.jpa.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.beans.factory.annotation.Autowired; - -import com.aol.micro.server.auto.discovery.Rest; - -@Rest -@Path("/persistence") -public class PersistentResource { - - - private final SpringDataRepository dao; - - @Autowired - public PersistentResource(SpringDataRepository dao) { - - this.dao = dao; - } - - @GET - @Produces("text/plain") - @Path("/create") - public String createEntity() { - - SpringDataEntity saved = dao.save(SpringDataEntity.builder() - .name("test") - .value("value").build()); - - return "ok"; - } - @GET - @Produces("application/json") - @Path("/get") - public Iterable get(){ - - return dao.findAll(); - - - } - - -} \ No newline at end of file diff --git a/micro-hibernate/src/test/java/app/spring/data/jpa/com/aol/micro/server/SpringDataRepository.java b/micro-hibernate/src/test/java/app/spring/data/jpa/com/aol/micro/server/SpringDataRepository.java deleted file mode 100644 index 0eb79b503..000000000 --- a/micro-hibernate/src/test/java/app/spring/data/jpa/com/aol/micro/server/SpringDataRepository.java +++ /dev/null @@ -1,9 +0,0 @@ -package app.spring.data.jpa.com.aol.micro.server; - -import org.springframework.data.repository.CrudRepository; -import org.springframework.stereotype.Repository; - - -public interface SpringDataRepository extends CrudRepository { - -} diff --git a/micro-hibernate/src/test/java/app/spring/data/jpa/com/oath/micro/server/PersistentResource.java b/micro-hibernate/src/test/java/app/spring/data/jpa/com/oath/micro/server/PersistentResource.java new file mode 100644 index 000000000..a17e42136 --- /dev/null +++ b/micro-hibernate/src/test/java/app/spring/data/jpa/com/oath/micro/server/PersistentResource.java @@ -0,0 +1,46 @@ +package app.spring.data.jpa.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.beans.factory.annotation.Autowired; + +import com.oath.micro.server.auto.discovery.Rest; + +@Rest +@Path("/persistence") +public class PersistentResource { + + + private final SpringDataRepository dao; + + @Autowired + public PersistentResource(SpringDataRepository dao) { + + this.dao = dao; + } + + @GET + @Produces("text/plain") + @Path("/create") + public String createEntity() { + + SpringDataEntity saved = dao.save(SpringDataEntity.builder() + .name("test") + .value("value").build()); + + return "ok"; + } + @GET + @Produces("application/json") + @Path("/get") + public Iterable get(){ + + return dao.findAll(); + + + } + + +} \ No newline at end of file diff --git a/micro-hibernate/src/test/java/app/spring/data/jpa/com/aol/micro/server/SpringDataEntity.java b/micro-hibernate/src/test/java/app/spring/data/jpa/com/oath/micro/server/SpringDataEntity.java similarity index 95% rename from micro-hibernate/src/test/java/app/spring/data/jpa/com/aol/micro/server/SpringDataEntity.java rename to micro-hibernate/src/test/java/app/spring/data/jpa/com/oath/micro/server/SpringDataEntity.java index c2f681b01..320b16b2d 100644 --- a/micro-hibernate/src/test/java/app/spring/data/jpa/com/aol/micro/server/SpringDataEntity.java +++ b/micro-hibernate/src/test/java/app/spring/data/jpa/com/oath/micro/server/SpringDataEntity.java @@ -1,4 +1,4 @@ -package app.spring.data.jpa.com.aol.micro.server; +package app.spring.data.jpa.com.oath.micro.server; import static javax.persistence.GenerationType.IDENTITY; diff --git a/micro-hibernate/src/test/java/app/spring/data/jpa/com/oath/micro/server/SpringDataRepository.java b/micro-hibernate/src/test/java/app/spring/data/jpa/com/oath/micro/server/SpringDataRepository.java new file mode 100644 index 000000000..aabca1886 --- /dev/null +++ b/micro-hibernate/src/test/java/app/spring/data/jpa/com/oath/micro/server/SpringDataRepository.java @@ -0,0 +1,8 @@ +package app.spring.data.jpa.com.oath.micro.server; + +import org.springframework.data.repository.CrudRepository; + + +public interface SpringDataRepository extends CrudRepository { + +} diff --git a/micro-hibernate/src/test/java/app/spring/data/jpa/com/aol/micro/server/SpringDataTest.java b/micro-hibernate/src/test/java/app/spring/data/jpa/com/oath/micro/server/SpringDataTest.java similarity index 80% rename from micro-hibernate/src/test/java/app/spring/data/jpa/com/aol/micro/server/SpringDataTest.java rename to micro-hibernate/src/test/java/app/spring/data/jpa/com/oath/micro/server/SpringDataTest.java index c25f0a701..1adc18bd0 100644 --- a/micro-hibernate/src/test/java/app/spring/data/jpa/com/aol/micro/server/SpringDataTest.java +++ b/micro-hibernate/src/test/java/app/spring/data/jpa/com/oath/micro/server/SpringDataTest.java @@ -1,4 +1,4 @@ -package app.spring.data.jpa.com.aol.micro.server; +package app.spring.data.jpa.com.oath.micro.server; import static org.hamcrest.CoreMatchers.is; @@ -9,21 +9,20 @@ import org.junit.After; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Config; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.rest.client.nio.AsyncRestClient; -import com.aol.micro.server.testing.RestAgent; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Config; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.rest.client.nio.AsyncRestClient; +import com.oath.micro.server.testing.RestAgent; @Microserver(properties={"db.connection.driver","org.hsqldb.jdbcDriver", "db.connection.url","jdbc:hsqldb:mem:aname", "db.connection.username", "sa", "db.connection.dialect","org.hibernate.dialect.HSQLDialect", - "db.connection.ddl.auto","create-drop"}, entityScan="app.spring.data.jpa.com.aol.micro.server") + "db.connection.ddl.auto","create-drop"}, entityScan="app.spring.data.jpa.com.oath.micro.server") @EnableJpaRepositories public class SpringDataTest { diff --git a/micro-hibernate/src/test/java/com/aol/micro/server/testing/RestAgent.java b/micro-hibernate/src/test/java/com/aol/micro/server/testing/RestAgent.java deleted file mode 100644 index ce204f810..000000000 --- a/micro-hibernate/src/test/java/com/aol/micro/server/testing/RestAgent.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.aol.micro.server.testing; - -import java.util.List; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.Invocation.Builder; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; - -import com.aol.micro.server.rest.jackson.JacksonUtil; - -public class RestAgent { - - - public String getJson(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.get(String.class); - - } - - public String get(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.TEXT_PLAIN); - - return request.get(String.class); - - } - - public T post(String url, Object payload,Class type) { - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); - } - - -} diff --git a/micro-hibernate/src/test/java/com/oath/micro/server/testing/RestAgent.java b/micro-hibernate/src/test/java/com/oath/micro/server/testing/RestAgent.java new file mode 100644 index 000000000..b2b86303e --- /dev/null +++ b/micro-hibernate/src/test/java/com/oath/micro/server/testing/RestAgent.java @@ -0,0 +1,53 @@ +package com.oath.micro.server.testing; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.Invocation.Builder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; + +import com.oath.micro.server.rest.jackson.JacksonUtil; + +public class RestAgent { + + + public String getJson(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.get(String.class); + + } + + public String get(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.TEXT_PLAIN); + + return request.get(String.class); + + } + + public T post(String url, Object payload,Class type) { + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); + } + + +} diff --git a/micro-hikaricp/src/main/java/com/aol/micro/server/spring/HikariCPPlugin.java b/micro-hikaricp/src/main/java/com/aol/micro/server/spring/HikariCPPlugin.java deleted file mode 100644 index f1452b769..000000000 --- a/micro-hikaricp/src/main/java/com/aol/micro/server/spring/HikariCPPlugin.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.aol.micro.server.spring; - - -import com.aol.micro.server.Plugin; -import com.aol.micro.server.spring.datasource.HikariCPConfig; -import com.aol.micro.server.spring.datasource.HikariCPDataSourceBuilder; -import cyclops.collections.immutable.PersistentSetX; -import cyclops.collections.mutable.SetX; - -import java.util.Set; - -/** - * - * @author kewang - * - */ -public class HikariCPPlugin implements Plugin { - - @Override - public Set springClasses() { - return SetX.of(HikariCPConfig.class, HikariCPDataSourceBuilder.class); - } - - - -} diff --git a/micro-hikaricp/src/main/java/com/oath/micro/server/spring/HikariCPPlugin.java b/micro-hikaricp/src/main/java/com/oath/micro/server/spring/HikariCPPlugin.java new file mode 100644 index 000000000..62b7c0968 --- /dev/null +++ b/micro-hikaricp/src/main/java/com/oath/micro/server/spring/HikariCPPlugin.java @@ -0,0 +1,25 @@ +package com.oath.micro.server.spring; + + +import com.oath.micro.server.Plugin; +import com.oath.micro.server.spring.datasource.HikariCPConfig; +import com.oath.micro.server.spring.datasource.HikariCPDataSourceBuilder; +import cyclops.collections.mutable.SetX; + +import java.util.Set; + +/** + * + * @author kewang + * + */ +public class HikariCPPlugin implements Plugin { + + @Override + public Set springClasses() { + return SetX.of(HikariCPConfig.class, HikariCPDataSourceBuilder.class); + } + + + +} diff --git a/micro-hikaricp/src/main/java/com/aol/micro/server/spring/datasource/HikariCPConfig.java b/micro-hikaricp/src/main/java/com/oath/micro/server/spring/datasource/HikariCPConfig.java similarity index 93% rename from micro-hikaricp/src/main/java/com/aol/micro/server/spring/datasource/HikariCPConfig.java rename to micro-hikaricp/src/main/java/com/oath/micro/server/spring/datasource/HikariCPConfig.java index d105fc849..00188b31e 100644 --- a/micro-hikaricp/src/main/java/com/aol/micro/server/spring/datasource/HikariCPConfig.java +++ b/micro-hikaricp/src/main/java/com/oath/micro/server/spring/datasource/HikariCPConfig.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.spring.datasource; +package com.oath.micro.server.spring.datasource; import lombok.Getter; import lombok.Builder; diff --git a/micro-hikaricp/src/main/java/com/aol/micro/server/spring/datasource/HikariCPDataSourceBuilder.java b/micro-hikaricp/src/main/java/com/oath/micro/server/spring/datasource/HikariCPDataSourceBuilder.java similarity index 95% rename from micro-hikaricp/src/main/java/com/aol/micro/server/spring/datasource/HikariCPDataSourceBuilder.java rename to micro-hikaricp/src/main/java/com/oath/micro/server/spring/datasource/HikariCPDataSourceBuilder.java index 5104b8ab8..4cc1e26ab 100644 --- a/micro-hikaricp/src/main/java/com/aol/micro/server/spring/datasource/HikariCPDataSourceBuilder.java +++ b/micro-hikaricp/src/main/java/com/oath/micro/server/spring/datasource/HikariCPDataSourceBuilder.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.spring.datasource; +package com.oath.micro.server.spring.datasource; import javax.annotation.Resource; import javax.sql.DataSource; diff --git a/micro-hikaricp/src/main/resources/META-INF/services/com.aol.micro.server.Plugin b/micro-hikaricp/src/main/resources/META-INF/services/com.aol.micro.server.Plugin deleted file mode 100644 index 59492eea5..000000000 --- a/micro-hikaricp/src/main/resources/META-INF/services/com.aol.micro.server.Plugin +++ /dev/null @@ -1 +0,0 @@ -com.aol.micro.server.spring.HikariCPPlugin \ No newline at end of file diff --git a/micro-hikaricp/src/main/resources/META-INF/services/com.oath.micro.server.Plugin b/micro-hikaricp/src/main/resources/META-INF/services/com.oath.micro.server.Plugin new file mode 100644 index 000000000..478fe9735 --- /dev/null +++ b/micro-hikaricp/src/main/resources/META-INF/services/com.oath.micro.server.Plugin @@ -0,0 +1 @@ +com.oath.micro.server.spring.HikariCPPlugin \ No newline at end of file diff --git a/micro-hikaricp/src/test/java/app/pure/jdbc/com/aol/micro/server/JdbcEntity.java b/micro-hikaricp/src/test/java/app/pure/jdbc/com/aol/micro/server/JdbcEntity.java deleted file mode 100644 index 2cc20b3df..000000000 --- a/micro-hikaricp/src/test/java/app/pure/jdbc/com/aol/micro/server/JdbcEntity.java +++ /dev/null @@ -1,27 +0,0 @@ -package app.pure.jdbc.com.aol.micro.server; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.Builder; - - - - -@Setter -@Getter -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class JdbcEntity implements java.io.Serializable { - - private static final long serialVersionUID = 1L; - - private Long id; - private String name; - private String value; - private int version; - - -} diff --git a/micro-hikaricp/src/test/java/app/pure/jdbc/com/aol/micro/server/JdbcRunnerTest.java b/micro-hikaricp/src/test/java/app/pure/jdbc/com/aol/micro/server/JdbcRunnerTest.java deleted file mode 100644 index ec6b573b7..000000000 --- a/micro-hikaricp/src/test/java/app/pure/jdbc/com/aol/micro/server/JdbcRunnerTest.java +++ /dev/null @@ -1,56 +0,0 @@ -package app.pure.jdbc.com.aol.micro.server; - - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.rest.client.nio.AsyncRestClient; -import com.aol.micro.server.testing.RestAgent; - -@Microserver(properties={"db.connection.driver","org.hsqldb.jdbcDriver", - "db.connection.url","jdbc:hsqldb:mem:aname", - "db.connection.username", "sa", - }) -public class JdbcRunnerTest { - - private final AsyncRestClient listClient = new AsyncRestClient(1000,1000).withResponse(JdbcEntity.class); - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - - @Before - public void startServer(){ - - - server = new MicroserverApp(()->"jdbc-app"); - server.start(); - rest.get("http://localhost:8080/jdbc-app/persistence/gen"); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException { - - assertThat(rest.get("http://localhost:8080/jdbc-app/persistence/create"),is("ok")); - assertThat(listClient.get("http://localhost:8080/jdbc-app/persistence/get").get(),is(JdbcEntity.class)); - - - } - - - -} diff --git a/micro-hikaricp/src/test/java/app/pure/jdbc/com/aol/micro/server/PersistentResource.java b/micro-hikaricp/src/test/java/app/pure/jdbc/com/aol/micro/server/PersistentResource.java deleted file mode 100644 index b826e9cd5..000000000 --- a/micro-hikaricp/src/test/java/app/pure/jdbc/com/aol/micro/server/PersistentResource.java +++ /dev/null @@ -1,48 +0,0 @@ -package app.pure.jdbc.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.BeanPropertyRowMapper; - -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.spring.datasource.jdbc.SQL; - -@Rest -@Path("/persistence") -public class PersistentResource { - - private final SQL dao; - - @Autowired - public PersistentResource(SQL dao) { - - this.dao = dao; - } - @GET - @Produces("text/plain") - @Path("/gen") - public String gen() { - dao.getJdbc().execute("create table t_jdbc(id bigint,name varchar(255),value varchar(255),version int);"); - - return "ok"; - } - @GET - @Produces("text/plain") - @Path("/create") - public String createEntity() { - dao.getJdbc().update("insert into t_jdbc VALUES (1,'hello','world',1)"); - - return "ok"; - } - - @GET - @Produces("application/json") - @Path("/get") - public JdbcEntity get() { - return dao.getJdbc(). queryForObject("select * from t_jdbc", new BeanPropertyRowMapper(JdbcEntity.class)); - } - -} \ No newline at end of file diff --git a/micro-hikaricp/src/test/java/app/pure/jdbc/com/oath/micro/server/JdbcEntity.java b/micro-hikaricp/src/test/java/app/pure/jdbc/com/oath/micro/server/JdbcEntity.java new file mode 100644 index 000000000..c92fd662b --- /dev/null +++ b/micro-hikaricp/src/test/java/app/pure/jdbc/com/oath/micro/server/JdbcEntity.java @@ -0,0 +1,27 @@ +package app.pure.jdbc.com.oath.micro.server; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.Builder; + + + + +@Setter +@Getter +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class JdbcEntity implements java.io.Serializable { + + private static final long serialVersionUID = 1L; + + private Long id; + private String name; + private String value; + private int version; + + +} diff --git a/micro-hikaricp/src/test/java/app/pure/jdbc/com/oath/micro/server/JdbcRunnerTest.java b/micro-hikaricp/src/test/java/app/pure/jdbc/com/oath/micro/server/JdbcRunnerTest.java new file mode 100644 index 000000000..08c384ca7 --- /dev/null +++ b/micro-hikaricp/src/test/java/app/pure/jdbc/com/oath/micro/server/JdbcRunnerTest.java @@ -0,0 +1,56 @@ +package app.pure.jdbc.com.oath.micro.server; + + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.rest.client.nio.AsyncRestClient; +import com.oath.micro.server.testing.RestAgent; + +@Microserver(properties={"db.connection.driver","org.hsqldb.jdbcDriver", + "db.connection.url","jdbc:hsqldb:mem:aname", + "db.connection.username", "sa", + }) +public class JdbcRunnerTest { + + private final AsyncRestClient listClient = new AsyncRestClient(1000,1000).withResponse(JdbcEntity.class); + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + + @Before + public void startServer(){ + + + server = new MicroserverApp(()->"jdbc-app"); + server.start(); + rest.get("http://localhost:8080/jdbc-app/persistence/gen"); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException { + + assertThat(rest.get("http://localhost:8080/jdbc-app/persistence/create"),is("ok")); + assertThat(listClient.get("http://localhost:8080/jdbc-app/persistence/get").get(),is(JdbcEntity.class)); + + + } + + + +} diff --git a/micro-hikaricp/src/test/java/app/pure/jdbc/com/oath/micro/server/PersistentResource.java b/micro-hikaricp/src/test/java/app/pure/jdbc/com/oath/micro/server/PersistentResource.java new file mode 100644 index 000000000..869898590 --- /dev/null +++ b/micro-hikaricp/src/test/java/app/pure/jdbc/com/oath/micro/server/PersistentResource.java @@ -0,0 +1,48 @@ +package app.pure.jdbc.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.BeanPropertyRowMapper; + +import com.oath.micro.server.auto.discovery.Rest; +import com.oath.micro.server.spring.datasource.jdbc.SQL; + +@Rest +@Path("/persistence") +public class PersistentResource { + + private final SQL dao; + + @Autowired + public PersistentResource(SQL dao) { + + this.dao = dao; + } + @GET + @Produces("text/plain") + @Path("/gen") + public String gen() { + dao.getJdbc().execute("create table t_jdbc(id bigint,name varchar(255),value varchar(255),version int);"); + + return "ok"; + } + @GET + @Produces("text/plain") + @Path("/create") + public String createEntity() { + dao.getJdbc().update("insert into t_jdbc VALUES (1,'hello','world',1)"); + + return "ok"; + } + + @GET + @Produces("application/json") + @Path("/get") + public JdbcEntity get() { + return dao.getJdbc(). queryForObject("select * from t_jdbc", new BeanPropertyRowMapper(JdbcEntity.class)); + } + +} \ No newline at end of file diff --git a/micro-hikaricp/src/test/java/com/aol/micro/server/testing/RestAgent.java b/micro-hikaricp/src/test/java/com/aol/micro/server/testing/RestAgent.java deleted file mode 100644 index ce204f810..000000000 --- a/micro-hikaricp/src/test/java/com/aol/micro/server/testing/RestAgent.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.aol.micro.server.testing; - -import java.util.List; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.Invocation.Builder; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; - -import com.aol.micro.server.rest.jackson.JacksonUtil; - -public class RestAgent { - - - public String getJson(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.get(String.class); - - } - - public String get(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.TEXT_PLAIN); - - return request.get(String.class); - - } - - public T post(String url, Object payload,Class type) { - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); - } - - -} diff --git a/micro-hikaricp/src/test/java/com/aol/micro/server/HikariCPConfigTest.java b/micro-hikaricp/src/test/java/com/oath/micro/server/HikariCPConfigTest.java similarity index 85% rename from micro-hikaricp/src/test/java/com/aol/micro/server/HikariCPConfigTest.java rename to micro-hikaricp/src/test/java/com/oath/micro/server/HikariCPConfigTest.java index 6f8730511..a62aa6951 100644 --- a/micro-hikaricp/src/test/java/com/aol/micro/server/HikariCPConfigTest.java +++ b/micro-hikaricp/src/test/java/com/oath/micro/server/HikariCPConfigTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server; +package com.oath.micro.server; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; @@ -7,7 +7,7 @@ import org.junit.Before; import org.junit.Test; -import com.aol.micro.server.spring.datasource.HikariCPConfig; +import com.oath.micro.server.spring.datasource.HikariCPConfig; public class HikariCPConfigTest { diff --git a/micro-hikaricp/src/test/java/com/oath/micro/server/testing/RestAgent.java b/micro-hikaricp/src/test/java/com/oath/micro/server/testing/RestAgent.java new file mode 100644 index 000000000..b2b86303e --- /dev/null +++ b/micro-hikaricp/src/test/java/com/oath/micro/server/testing/RestAgent.java @@ -0,0 +1,53 @@ +package com.oath.micro.server.testing; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.Invocation.Builder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; + +import com.oath.micro.server.rest.jackson.JacksonUtil; + +public class RestAgent { + + + public String getJson(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.get(String.class); + + } + + public String get(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.TEXT_PLAIN); + + return request.get(String.class); + + } + + public T post(String url, Object payload,Class type) { + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); + } + + +} diff --git a/micro-ip-tracker/src/main/java/com/aol/micro/server/ip/tracker/IPTrackerPlugin.java b/micro-ip-tracker/src/main/java/com/aol/micro/server/ip/tracker/IPTrackerPlugin.java deleted file mode 100644 index f404ce9ed..000000000 --- a/micro-ip-tracker/src/main/java/com/aol/micro/server/ip/tracker/IPTrackerPlugin.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.aol.micro.server.ip.tracker; - -import com.aol.micro.server.Plugin; -import cyclops.collections.immutable.PersistentSetX; -import cyclops.collections.mutable.SetX; - -import java.util.Set; - - -public class IPTrackerPlugin implements Plugin{ - - @Override - public Set springClasses() { - return SetX.of(BeanConfiguration.class); - - } - - - - -} diff --git a/micro-ip-tracker/src/main/java/com/aol/micro/server/ip/tracker/BeanConfiguration.java b/micro-ip-tracker/src/main/java/com/oath/micro/server/ip/tracker/BeanConfiguration.java similarity index 88% rename from micro-ip-tracker/src/main/java/com/aol/micro/server/ip/tracker/BeanConfiguration.java rename to micro-ip-tracker/src/main/java/com/oath/micro/server/ip/tracker/BeanConfiguration.java index 4889715ea..645d08396 100644 --- a/micro-ip-tracker/src/main/java/com/aol/micro/server/ip/tracker/BeanConfiguration.java +++ b/micro-ip-tracker/src/main/java/com/oath/micro/server/ip/tracker/BeanConfiguration.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.ip.tracker; +package com.oath.micro.server.ip.tracker; import javax.servlet.Filter; @@ -8,7 +8,7 @@ import org.springframework.context.annotation.Configuration; -import com.aol.micro.server.auto.discovery.FilterConfiguration; +import com.oath.micro.server.auto.discovery.FilterConfiguration; @Configuration public class BeanConfiguration { diff --git a/micro-ip-tracker/src/main/java/com/oath/micro/server/ip/tracker/IPTrackerPlugin.java b/micro-ip-tracker/src/main/java/com/oath/micro/server/ip/tracker/IPTrackerPlugin.java new file mode 100644 index 000000000..90706a3ba --- /dev/null +++ b/micro-ip-tracker/src/main/java/com/oath/micro/server/ip/tracker/IPTrackerPlugin.java @@ -0,0 +1,20 @@ +package com.oath.micro.server.ip.tracker; + +import com.oath.micro.server.Plugin; +import cyclops.collections.mutable.SetX; + +import java.util.Set; + + +public class IPTrackerPlugin implements Plugin{ + + @Override + public Set springClasses() { + return SetX.of(BeanConfiguration.class); + + } + + + + +} diff --git a/micro-ip-tracker/src/main/java/com/aol/micro/server/ip/tracker/QueryIPRetriever.java b/micro-ip-tracker/src/main/java/com/oath/micro/server/ip/tracker/QueryIPRetriever.java similarity index 94% rename from micro-ip-tracker/src/main/java/com/aol/micro/server/ip/tracker/QueryIPRetriever.java rename to micro-ip-tracker/src/main/java/com/oath/micro/server/ip/tracker/QueryIPRetriever.java index cc9e01fe1..3a2a3657d 100644 --- a/micro-ip-tracker/src/main/java/com/aol/micro/server/ip/tracker/QueryIPRetriever.java +++ b/micro-ip-tracker/src/main/java/com/oath/micro/server/ip/tracker/QueryIPRetriever.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.ip.tracker; +package com.oath.micro.server.ip.tracker; import java.io.IOException; import java.util.Optional; @@ -13,8 +13,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import org.springframework.util.StringUtils; diff --git a/micro-ip-tracker/src/main/resources/META-INF/services/com.aol.micro.server.Plugin b/micro-ip-tracker/src/main/resources/META-INF/services/com.aol.micro.server.Plugin deleted file mode 100644 index 2656b2d58..000000000 --- a/micro-ip-tracker/src/main/resources/META-INF/services/com.aol.micro.server.Plugin +++ /dev/null @@ -1 +0,0 @@ -com.aol.micro.server.ip.tracker.IPTrackerPlugin \ No newline at end of file diff --git a/micro-ip-tracker/src/main/resources/META-INF/services/com.oath.micro.server.Plugin b/micro-ip-tracker/src/main/resources/META-INF/services/com.oath.micro.server.Plugin new file mode 100644 index 000000000..a200a6cb9 --- /dev/null +++ b/micro-ip-tracker/src/main/resources/META-INF/services/com.oath.micro.server.Plugin @@ -0,0 +1 @@ +com.oath.micro.server.ip.tracker.IPTrackerPlugin \ No newline at end of file diff --git a/micro-ip-tracker/src/test/java/app/simple/com/aol/micro/server/SimpleApp.java b/micro-ip-tracker/src/test/java/app/simple/com/aol/micro/server/SimpleApp.java deleted file mode 100644 index 700a2c778..000000000 --- a/micro-ip-tracker/src/test/java/app/simple/com/aol/micro/server/SimpleApp.java +++ /dev/null @@ -1,18 +0,0 @@ -package app.simple.com.aol.micro.server; - -import java.util.Arrays; - -import org.glassfish.jersey.media.multipart.MultiPartFeature; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.module.ConfigurableModule; - -public class SimpleApp { - - public static void main(String[] args){ - - new MicroserverApp(()-> "simple-app").run(); - } - - -} diff --git a/micro-ip-tracker/src/test/java/app/simple/com/aol/micro/server/SimpleRunnerTest.java b/micro-ip-tracker/src/test/java/app/simple/com/aol/micro/server/SimpleRunnerTest.java deleted file mode 100644 index f18021199..000000000 --- a/micro-ip-tracker/src/test/java/app/simple/com/aol/micro/server/SimpleRunnerTest.java +++ /dev/null @@ -1,55 +0,0 @@ -package app.simple.com.aol.micro.server; - - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.Arrays; -import java.util.concurrent.ExecutionException; - -import org.glassfish.jersey.media.multipart.MultiPartFeature; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.testing.RestAgent; - -@Microserver -public class SimpleRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer(){ - server = new MicroserverApp(ConfigurableModule - .builder() - .context("simple-app") - .defaultResources(Arrays.asList(MultiPartFeature.class)) - .build()); - - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - - - assertThat(rest.get("http://localhost:8080/simple-app/status/ping"),is("127.0.0.1")); - - - } - - - -} diff --git a/micro-ip-tracker/src/test/java/app/simple/com/aol/micro/server/SimpleStatusResource.java b/micro-ip-tracker/src/test/java/app/simple/com/aol/micro/server/SimpleStatusResource.java deleted file mode 100644 index 9966694cb..000000000 --- a/micro-ip-tracker/src/test/java/app/simple/com/aol/micro/server/SimpleStatusResource.java +++ /dev/null @@ -1,40 +0,0 @@ -package app.simple.com.aol.micro.server; - -import java.io.InputStream; - -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; - -import org.glassfish.jersey.media.multipart.FormDataContentDisposition; -import org.glassfish.jersey.media.multipart.FormDataParam; - -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.ip.tracker.QueryIPRetriever; - -@Rest -@Path("/status") -public class SimpleStatusResource { - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - - return QueryIPRetriever.getIpAddress(); - } - - @POST - @Consumes(MediaType.MULTIPART_FORM_DATA) - @Produces(MediaType.TEXT_PLAIN) - @Path("/file") - public String create( - @FormDataParam("file") InputStream fileInputStream, - @FormDataParam("file") FormDataContentDisposition contentDispositionHeader) { - - return "done"; - } -} \ No newline at end of file diff --git a/micro-ip-tracker/src/test/java/app/simple/com/oath/micro/server/SimpleApp.java b/micro-ip-tracker/src/test/java/app/simple/com/oath/micro/server/SimpleApp.java new file mode 100644 index 000000000..e82a92291 --- /dev/null +++ b/micro-ip-tracker/src/test/java/app/simple/com/oath/micro/server/SimpleApp.java @@ -0,0 +1,13 @@ +package app.simple.com.oath.micro.server; + +import com.oath.micro.server.MicroserverApp; + +public class SimpleApp { + + public static void main(String[] args){ + + new MicroserverApp(()-> "simple-app").run(); + } + + +} diff --git a/micro-ip-tracker/src/test/java/app/simple/com/oath/micro/server/SimpleRunnerTest.java b/micro-ip-tracker/src/test/java/app/simple/com/oath/micro/server/SimpleRunnerTest.java new file mode 100644 index 000000000..f3bc236b5 --- /dev/null +++ b/micro-ip-tracker/src/test/java/app/simple/com/oath/micro/server/SimpleRunnerTest.java @@ -0,0 +1,55 @@ +package app.simple.com.oath.micro.server; + + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.Arrays; +import java.util.concurrent.ExecutionException; + +import org.glassfish.jersey.media.multipart.MultiPartFeature; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.module.ConfigurableModule; +import com.oath.micro.server.testing.RestAgent; + +@Microserver +public class SimpleRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer(){ + server = new MicroserverApp(ConfigurableModule + .builder() + .context("simple-app") + .defaultResources(Arrays.asList(MultiPartFeature.class)) + .build()); + + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + + + assertThat(rest.get("http://localhost:8080/simple-app/status/ping"),is("127.0.0.1")); + + + } + + + +} diff --git a/micro-ip-tracker/src/test/java/app/simple/com/oath/micro/server/SimpleStatusResource.java b/micro-ip-tracker/src/test/java/app/simple/com/oath/micro/server/SimpleStatusResource.java new file mode 100644 index 000000000..01a9fb88a --- /dev/null +++ b/micro-ip-tracker/src/test/java/app/simple/com/oath/micro/server/SimpleStatusResource.java @@ -0,0 +1,40 @@ +package app.simple.com.oath.micro.server; + +import java.io.InputStream; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +import org.glassfish.jersey.media.multipart.FormDataContentDisposition; +import org.glassfish.jersey.media.multipart.FormDataParam; + +import com.oath.micro.server.auto.discovery.Rest; +import com.oath.micro.server.ip.tracker.QueryIPRetriever; + +@Rest +@Path("/status") +public class SimpleStatusResource { + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + + return QueryIPRetriever.getIpAddress(); + } + + @POST + @Consumes(MediaType.MULTIPART_FORM_DATA) + @Produces(MediaType.TEXT_PLAIN) + @Path("/file") + public String create( + @FormDataParam("file") InputStream fileInputStream, + @FormDataParam("file") FormDataContentDisposition contentDispositionHeader) { + + return "done"; + } +} \ No newline at end of file diff --git a/micro-ip-tracker/src/test/java/com/aol/micro/server/testing/RestAgent.java b/micro-ip-tracker/src/test/java/com/aol/micro/server/testing/RestAgent.java deleted file mode 100644 index ce204f810..000000000 --- a/micro-ip-tracker/src/test/java/com/aol/micro/server/testing/RestAgent.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.aol.micro.server.testing; - -import java.util.List; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.Invocation.Builder; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; - -import com.aol.micro.server.rest.jackson.JacksonUtil; - -public class RestAgent { - - - public String getJson(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.get(String.class); - - } - - public String get(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.TEXT_PLAIN); - - return request.get(String.class); - - } - - public T post(String url, Object payload,Class type) { - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); - } - - -} diff --git a/micro-ip-tracker/src/test/java/com/aol/micro/server/ip/tracker/QueryIPRetrieverTest.java b/micro-ip-tracker/src/test/java/com/oath/micro/server/ip/tracker/QueryIPRetrieverTest.java similarity index 99% rename from micro-ip-tracker/src/test/java/com/aol/micro/server/ip/tracker/QueryIPRetrieverTest.java rename to micro-ip-tracker/src/test/java/com/oath/micro/server/ip/tracker/QueryIPRetrieverTest.java index f58e2783a..0cbacb997 100644 --- a/micro-ip-tracker/src/test/java/com/aol/micro/server/ip/tracker/QueryIPRetrieverTest.java +++ b/micro-ip-tracker/src/test/java/com/oath/micro/server/ip/tracker/QueryIPRetrieverTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.ip.tracker; +package com.oath.micro.server.ip.tracker; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; diff --git a/micro-ip-tracker/src/test/java/com/oath/micro/server/testing/RestAgent.java b/micro-ip-tracker/src/test/java/com/oath/micro/server/testing/RestAgent.java new file mode 100644 index 000000000..b2b86303e --- /dev/null +++ b/micro-ip-tracker/src/test/java/com/oath/micro/server/testing/RestAgent.java @@ -0,0 +1,53 @@ +package com.oath.micro.server.testing; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.Invocation.Builder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; + +import com.oath.micro.server.rest.jackson.JacksonUtil; + +public class RestAgent { + + + public String getJson(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.get(String.class); + + } + + public String get(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.TEXT_PLAIN); + + return request.get(String.class); + + } + + public T post(String url, Object payload,Class type) { + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); + } + + +} diff --git a/micro-jackson-configuration/src/main/java/com/aol/micro/server/jackson/CoreJacksonConfigurator.java b/micro-jackson-configuration/src/main/java/com/oath/micro/server/jackson/CoreJacksonConfigurator.java similarity index 93% rename from micro-jackson-configuration/src/main/java/com/aol/micro/server/jackson/CoreJacksonConfigurator.java rename to micro-jackson-configuration/src/main/java/com/oath/micro/server/jackson/CoreJacksonConfigurator.java index eea5bf4fd..f3d94be57 100644 --- a/micro-jackson-configuration/src/main/java/com/aol/micro/server/jackson/CoreJacksonConfigurator.java +++ b/micro-jackson-configuration/src/main/java/com/oath/micro/server/jackson/CoreJacksonConfigurator.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.jackson; +package com.oath.micro.server.jackson; import java.util.Optional; @@ -6,7 +6,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; -import com.aol.micro.server.PluginLoader; +import com.oath.micro.server.PluginLoader; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; diff --git a/micro-jackson-configuration/src/main/java/com/aol/micro/server/jackson/JacksonConfigurers.java b/micro-jackson-configuration/src/main/java/com/oath/micro/server/jackson/JacksonConfigurers.java similarity index 84% rename from micro-jackson-configuration/src/main/java/com/aol/micro/server/jackson/JacksonConfigurers.java rename to micro-jackson-configuration/src/main/java/com/oath/micro/server/jackson/JacksonConfigurers.java index da9eaf097..b4f22b3ea 100644 --- a/micro-jackson-configuration/src/main/java/com/aol/micro/server/jackson/JacksonConfigurers.java +++ b/micro-jackson-configuration/src/main/java/com/oath/micro/server/jackson/JacksonConfigurers.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.jackson; +package com.oath.micro.server.jackson; import java.util.List; @@ -7,7 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import com.aol.micro.server.rest.jackson.JacksonUtil; +import com.oath.micro.server.rest.jackson.JacksonUtil; @Component public class JacksonConfigurers { diff --git a/micro-jackson-configuration/src/main/java/com/aol/micro/server/jackson/JacksonMapperConfigurator.java b/micro-jackson-configuration/src/main/java/com/oath/micro/server/jackson/JacksonMapperConfigurator.java similarity index 81% rename from micro-jackson-configuration/src/main/java/com/aol/micro/server/jackson/JacksonMapperConfigurator.java rename to micro-jackson-configuration/src/main/java/com/oath/micro/server/jackson/JacksonMapperConfigurator.java index 09cf69177..261cc59d5 100644 --- a/micro-jackson-configuration/src/main/java/com/aol/micro/server/jackson/JacksonMapperConfigurator.java +++ b/micro-jackson-configuration/src/main/java/com/oath/micro/server/jackson/JacksonMapperConfigurator.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.jackson; +package com.oath.micro.server.jackson; import java.util.function.Consumer; import com.fasterxml.jackson.databind.ObjectMapper; diff --git a/micro-jackson-configuration/src/main/java/com/aol/micro/server/jackson/JacksonPlugin.java b/micro-jackson-configuration/src/main/java/com/oath/micro/server/jackson/JacksonPlugin.java similarity index 76% rename from micro-jackson-configuration/src/main/java/com/aol/micro/server/jackson/JacksonPlugin.java rename to micro-jackson-configuration/src/main/java/com/oath/micro/server/jackson/JacksonPlugin.java index 0a9007e71..310157e52 100644 --- a/micro-jackson-configuration/src/main/java/com/aol/micro/server/jackson/JacksonPlugin.java +++ b/micro-jackson-configuration/src/main/java/com/oath/micro/server/jackson/JacksonPlugin.java @@ -1,11 +1,10 @@ -package com.aol.micro.server.jackson; +package com.oath.micro.server.jackson; -import com.aol.micro.server.Plugin; -import com.aol.micro.server.rest.jackson.JacksonFeature; +import com.oath.micro.server.Plugin; +import com.oath.micro.server.rest.jackson.JacksonFeature; import com.fasterxml.jackson.databind.Module; import com.fasterxml.jackson.datatype.pcollections.PCollectionsModule; -import cyclops.collections.immutable.PersistentSetX; import cyclops.collections.mutable.SetX; import java.util.Set; diff --git a/micro-jackson-configuration/src/main/java/com/aol/micro/server/rest/jackson/JacksonFeature.java b/micro-jackson-configuration/src/main/java/com/oath/micro/server/rest/jackson/JacksonFeature.java similarity index 89% rename from micro-jackson-configuration/src/main/java/com/aol/micro/server/rest/jackson/JacksonFeature.java rename to micro-jackson-configuration/src/main/java/com/oath/micro/server/rest/jackson/JacksonFeature.java index bf9f852c9..c3f932723 100644 --- a/micro-jackson-configuration/src/main/java/com/aol/micro/server/rest/jackson/JacksonFeature.java +++ b/micro-jackson-configuration/src/main/java/com/oath/micro/server/rest/jackson/JacksonFeature.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.rest.jackson; +package com.oath.micro.server.rest.jackson; import java.util.Map; @@ -7,8 +7,8 @@ import javax.ws.rs.ext.MessageBodyReader; import javax.ws.rs.ext.MessageBodyWriter; -import com.aol.micro.server.Plugin; -import com.aol.micro.server.PluginLoader; +import com.oath.micro.server.Plugin; +import com.oath.micro.server.PluginLoader; import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider; diff --git a/micro-jackson-configuration/src/main/java/com/aol/micro/server/rest/jackson/JacksonUtil.java b/micro-jackson-configuration/src/main/java/com/oath/micro/server/rest/jackson/JacksonUtil.java similarity index 94% rename from micro-jackson-configuration/src/main/java/com/aol/micro/server/rest/jackson/JacksonUtil.java rename to micro-jackson-configuration/src/main/java/com/oath/micro/server/rest/jackson/JacksonUtil.java index 3023c174f..9694820b8 100644 --- a/micro-jackson-configuration/src/main/java/com/aol/micro/server/rest/jackson/JacksonUtil.java +++ b/micro-jackson-configuration/src/main/java/com/oath/micro/server/rest/jackson/JacksonUtil.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.rest.jackson; +package com.oath.micro.server.rest.jackson; import java.util.Arrays; @@ -10,8 +10,8 @@ import org.slf4j.LoggerFactory; -import com.aol.micro.server.jackson.CoreJacksonConfigurator; -import com.aol.micro.server.jackson.JacksonMapperConfigurator; +import com.oath.micro.server.jackson.CoreJacksonConfigurator; +import com.oath.micro.server.jackson.JacksonMapperConfigurator; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.ObjectMapper; diff --git a/micro-jackson-configuration/src/main/java/com/aol/micro/server/rest/providers/ObjectMapperProvider.java b/micro-jackson-configuration/src/main/java/com/oath/micro/server/rest/providers/ObjectMapperProvider.java similarity index 80% rename from micro-jackson-configuration/src/main/java/com/aol/micro/server/rest/providers/ObjectMapperProvider.java rename to micro-jackson-configuration/src/main/java/com/oath/micro/server/rest/providers/ObjectMapperProvider.java index 3cd259af2..acd8e858f 100644 --- a/micro-jackson-configuration/src/main/java/com/aol/micro/server/rest/providers/ObjectMapperProvider.java +++ b/micro-jackson-configuration/src/main/java/com/oath/micro/server/rest/providers/ObjectMapperProvider.java @@ -1,11 +1,11 @@ -package com.aol.micro.server.rest.providers; +package com.oath.micro.server.rest.providers; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.ext.ContextResolver; import javax.ws.rs.ext.Provider; -import com.aol.micro.server.rest.jackson.JacksonUtil; +import com.oath.micro.server.rest.jackson.JacksonUtil; import com.fasterxml.jackson.databind.ObjectMapper; @Provider diff --git a/micro-jackson-configuration/src/main/resources/META-INF/services/com.aol.micro.server.Plugin b/micro-jackson-configuration/src/main/resources/META-INF/services/com.aol.micro.server.Plugin deleted file mode 100644 index 6d7a2d9d5..000000000 --- a/micro-jackson-configuration/src/main/resources/META-INF/services/com.aol.micro.server.Plugin +++ /dev/null @@ -1 +0,0 @@ -com.aol.micro.server.jackson.JacksonPlugin \ No newline at end of file diff --git a/micro-jackson-configuration/src/main/resources/META-INF/services/com.oath.micro.server.Plugin b/micro-jackson-configuration/src/main/resources/META-INF/services/com.oath.micro.server.Plugin new file mode 100644 index 000000000..e17965f72 --- /dev/null +++ b/micro-jackson-configuration/src/main/resources/META-INF/services/com.oath.micro.server.Plugin @@ -0,0 +1 @@ +com.oath.micro.server.jackson.JacksonPlugin \ No newline at end of file diff --git a/micro-jackson-configuration/src/test/java/com/aol/micro/server/rest/JacksonUtilTest.java b/micro-jackson-configuration/src/test/java/com/aol/micro/server/rest/JacksonUtilTest.java deleted file mode 100644 index 12b24c81b..000000000 --- a/micro-jackson-configuration/src/test/java/com/aol/micro/server/rest/JacksonUtilTest.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.aol.micro.server.rest; - -import static junit.framework.Assert.assertTrue; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.junit.Assert.assertThat; - -import java.util.ArrayList; -import java.util.List; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -import cyclops.collections.immutable.LinkedListX; -import cyclops.data.Seq; -import org.junit.Ignore; -import org.junit.Test; - - - -import com.aol.micro.server.rest.jackson.JacksonUtil; - -import lombok.Getter; -import lombok.Setter; - -public class JacksonUtilTest { - - @Test - public void generateSampleRequest() { - - DummyQueryRequest request = new DummyQueryRequest(); - request.getData() - .add("blah"); - - assertTrue(JacksonUtil.serializeToJson(request) - .contains("strData")); - - } - - @Test - public void serialiseAndDeserialise() { - DummyQueryRequest request = new DummyQueryRequest(); - request.getData() - .add("blah"); - String requestStr = (String) JacksonUtil.serializeToJsonLogFailure(request); - DummyQueryRequest requestDeserialised = JacksonUtil.convertFromJson(requestStr, DummyQueryRequest.class); - assertTrue(request.getData() - .contains("blah")); - } - - @Test @Ignore - public void serializeToPersistentList() { - - LinkedListX list = LinkedListX.of(1, 2, 3, 4); - String jsonString = JacksonUtil.serializeToJson(list); - - Seq stack = JacksonUtil.convertFromJson(jsonString, Seq.class); - - assertThat(stack, equalTo(list.reverse())); - } - -} - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlRootElement(name = "queryRequest") -@XmlType(name = "") -class DummyQueryRequest { - - @XmlElement(name = "strData") - @Getter - @Setter - private List data = new ArrayList(); - -} diff --git a/micro-jackson-configuration/src/test/java/com/aol/micro/server/rest/MyEntity.java b/micro-jackson-configuration/src/test/java/com/aol/micro/server/rest/MyEntity.java deleted file mode 100644 index b6a7a0ec7..000000000 --- a/micro-jackson-configuration/src/test/java/com/aol/micro/server/rest/MyEntity.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.aol.micro.server.rest; - -import lombok.EqualsAndHashCode; -import lombok.Getter; - -@EqualsAndHashCode -@Getter -public class MyEntity { - - private final String name ="myEntity"; - -} diff --git a/micro-jackson-configuration/src/test/java/com/aol/micro/server/testing/RestAgent.java b/micro-jackson-configuration/src/test/java/com/aol/micro/server/testing/RestAgent.java deleted file mode 100644 index 99c4717a1..000000000 --- a/micro-jackson-configuration/src/test/java/com/aol/micro/server/testing/RestAgent.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.aol.micro.server.testing; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.Invocation.Builder; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import com.aol.micro.server.rest.jackson.JacksonUtil; - -public class RestAgent { - - - public String getJson(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.get(String.class); - - } - - public String get(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.TEXT_PLAIN); - - return request.get(String.class); - - } - - public T post(String url, Object payload,Class type) { - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); - } - public Response postString(String url, String payload) { - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.post(Entity.entity(payload,MediaType.APPLICATION_JSON)); - } - - -} diff --git a/micro-jackson-configuration/src/test/java/com/oath/micro/server/rest/JacksonUtilTest.java b/micro-jackson-configuration/src/test/java/com/oath/micro/server/rest/JacksonUtilTest.java new file mode 100644 index 000000000..f6698b357 --- /dev/null +++ b/micro-jackson-configuration/src/test/java/com/oath/micro/server/rest/JacksonUtilTest.java @@ -0,0 +1,76 @@ +package com.oath.micro.server.rest; + +import static junit.framework.Assert.assertTrue; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.junit.Assert.assertThat; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +import cyclops.collections.immutable.LinkedListX; +import cyclops.data.Seq; +import org.junit.Ignore; +import org.junit.Test; + + + +import com.oath.micro.server.rest.jackson.JacksonUtil; + +import lombok.Getter; +import lombok.Setter; + +public class JacksonUtilTest { + + @Test + public void generateSampleRequest() { + + DummyQueryRequest request = new DummyQueryRequest(); + request.getData() + .add("blah"); + + assertTrue(JacksonUtil.serializeToJson(request) + .contains("strData")); + + } + + @Test + public void serialiseAndDeserialise() { + DummyQueryRequest request = new DummyQueryRequest(); + request.getData() + .add("blah"); + String requestStr = (String) JacksonUtil.serializeToJsonLogFailure(request); + DummyQueryRequest requestDeserialised = JacksonUtil.convertFromJson(requestStr, DummyQueryRequest.class); + assertTrue(request.getData() + .contains("blah")); + } + + @Test @Ignore + public void serializeToPersistentList() { + + LinkedListX list = LinkedListX.of(1, 2, 3, 4); + String jsonString = JacksonUtil.serializeToJson(list); + + Seq stack = JacksonUtil.convertFromJson(jsonString, Seq.class); + + assertThat(stack, equalTo(list.reverse())); + } + +} + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlRootElement(name = "queryRequest") +@XmlType(name = "") +class DummyQueryRequest { + + @XmlElement(name = "strData") + @Getter + @Setter + private List data = new ArrayList(); + +} diff --git a/micro-jackson-configuration/src/test/java/com/oath/micro/server/rest/MyEntity.java b/micro-jackson-configuration/src/test/java/com/oath/micro/server/rest/MyEntity.java new file mode 100644 index 000000000..c691212ff --- /dev/null +++ b/micro-jackson-configuration/src/test/java/com/oath/micro/server/rest/MyEntity.java @@ -0,0 +1,12 @@ +package com.oath.micro.server.rest; + +import lombok.EqualsAndHashCode; +import lombok.Getter; + +@EqualsAndHashCode +@Getter +public class MyEntity { + + private final String name ="myEntity"; + +} diff --git a/micro-jackson-configuration/src/test/java/com/aol/micro/server/rest/providers/ObjectMapperProviderTest.java b/micro-jackson-configuration/src/test/java/com/oath/micro/server/rest/providers/ObjectMapperProviderTest.java similarity index 80% rename from micro-jackson-configuration/src/test/java/com/aol/micro/server/rest/providers/ObjectMapperProviderTest.java rename to micro-jackson-configuration/src/test/java/com/oath/micro/server/rest/providers/ObjectMapperProviderTest.java index de29bb468..0edc72365 100644 --- a/micro-jackson-configuration/src/test/java/com/aol/micro/server/rest/providers/ObjectMapperProviderTest.java +++ b/micro-jackson-configuration/src/test/java/com/oath/micro/server/rest/providers/ObjectMapperProviderTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.rest.providers; +package com.oath.micro.server.rest.providers; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; @@ -6,7 +6,7 @@ import org.junit.Before; import org.junit.Test; -import com.aol.micro.server.rest.jackson.JacksonUtil; +import com.oath.micro.server.rest.jackson.JacksonUtil; public class ObjectMapperProviderTest { diff --git a/micro-jackson-configuration/src/test/java/com/oath/micro/server/testing/RestAgent.java b/micro-jackson-configuration/src/test/java/com/oath/micro/server/testing/RestAgent.java new file mode 100644 index 000000000..adf56edef --- /dev/null +++ b/micro-jackson-configuration/src/test/java/com/oath/micro/server/testing/RestAgent.java @@ -0,0 +1,64 @@ +package com.oath.micro.server.testing; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.Invocation.Builder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import com.oath.micro.server.rest.jackson.JacksonUtil; + +public class RestAgent { + + + public String getJson(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.get(String.class); + + } + + public String get(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.TEXT_PLAIN); + + return request.get(String.class); + + } + + public T post(String url, Object payload,Class type) { + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); + } + public Response postString(String url, String payload) { + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.post(Entity.entity(payload,MediaType.APPLICATION_JSON)); + } + + +} diff --git a/micro-jdbc/src/main/java/com/aol/micro/server/spring/JdbcPlugin.java b/micro-jdbc/src/main/java/com/aol/micro/server/spring/JdbcPlugin.java deleted file mode 100644 index 97606bc98..000000000 --- a/micro-jdbc/src/main/java/com/aol/micro/server/spring/JdbcPlugin.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.aol.micro.server.spring; - -import java.util.Optional; -import java.util.Set; - - -import com.aol.micro.server.Plugin; -import com.aol.micro.server.spring.datasource.JdbcConfig; -import com.aol.micro.server.spring.datasource.jdbc.SQL; -import cyclops.collections.immutable.PersistentSetX; -import cyclops.collections.mutable.SetX; - -/** - * - * Collections of Spring configuration classes (Classes annotated with @Configuration) - * that configure various useful pieces of functionality - such as property file loading, - * datasources, scheduling etc - * - * @author johnmcclean - * - */ -public class JdbcPlugin implements Plugin { - - @Override - public Optional springDbConfigurer() { - return Optional.of(new SpringConfigurer()); - } - - @Override - public Set springClasses() { - return SetX.of(JdbcConfig.class, SQL.class); - } - - -} diff --git a/micro-jdbc/src/main/java/com/oath/micro/server/spring/JdbcPlugin.java b/micro-jdbc/src/main/java/com/oath/micro/server/spring/JdbcPlugin.java new file mode 100644 index 000000000..b3ac3dd60 --- /dev/null +++ b/micro-jdbc/src/main/java/com/oath/micro/server/spring/JdbcPlugin.java @@ -0,0 +1,34 @@ +package com.oath.micro.server.spring; + +import java.util.Optional; +import java.util.Set; + + +import com.oath.micro.server.Plugin; +import com.oath.micro.server.spring.datasource.JdbcConfig; +import com.oath.micro.server.spring.datasource.jdbc.SQL; +import cyclops.collections.mutable.SetX; + +/** + * + * Collections of Spring configuration classes (Classes annotated with @Configuration) + * that configure various useful pieces of functionality - such as property file loading, + * datasources, scheduling etc + * + * @author johnmcclean + * + */ +public class JdbcPlugin implements Plugin { + + @Override + public Optional springDbConfigurer() { + return Optional.of(new SpringConfigurer()); + } + + @Override + public Set springClasses() { + return SetX.of(JdbcConfig.class, SQL.class); + } + + +} diff --git a/micro-jdbc/src/main/java/com/aol/micro/server/spring/SpringConfigurer.java b/micro-jdbc/src/main/java/com/oath/micro/server/spring/SpringConfigurer.java similarity index 87% rename from micro-jdbc/src/main/java/com/aol/micro/server/spring/SpringConfigurer.java rename to micro-jdbc/src/main/java/com/oath/micro/server/spring/SpringConfigurer.java index 2c0f4e946..b9ab65152 100644 --- a/micro-jdbc/src/main/java/com/aol/micro/server/spring/SpringConfigurer.java +++ b/micro-jdbc/src/main/java/com/oath/micro/server/spring/SpringConfigurer.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.spring; +package com.oath.micro.server.spring; import java.util.Properties; @@ -9,8 +9,8 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; -import com.aol.micro.server.config.Config; -import com.aol.micro.server.spring.datasource.JdbcConfig; +import com.oath.micro.server.config.Config; +import com.oath.micro.server.spring.datasource.JdbcConfig; public class SpringConfigurer implements SpringDBConfig { diff --git a/micro-jdbc/src/main/java/com/aol/micro/server/spring/datasource/DataSourceBuilder.java b/micro-jdbc/src/main/java/com/oath/micro/server/spring/datasource/DataSourceBuilder.java similarity index 79% rename from micro-jdbc/src/main/java/com/aol/micro/server/spring/datasource/DataSourceBuilder.java rename to micro-jdbc/src/main/java/com/oath/micro/server/spring/datasource/DataSourceBuilder.java index 963bfb086..5c7e985b7 100644 --- a/micro-jdbc/src/main/java/com/aol/micro/server/spring/datasource/DataSourceBuilder.java +++ b/micro-jdbc/src/main/java/com/oath/micro/server/spring/datasource/DataSourceBuilder.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.spring.datasource; +package com.oath.micro.server.spring.datasource; import javax.sql.DataSource; diff --git a/micro-jdbc/src/main/java/com/aol/micro/server/spring/datasource/JdbcConfig.java b/micro-jdbc/src/main/java/com/oath/micro/server/spring/datasource/JdbcConfig.java similarity index 94% rename from micro-jdbc/src/main/java/com/aol/micro/server/spring/datasource/JdbcConfig.java rename to micro-jdbc/src/main/java/com/oath/micro/server/spring/datasource/JdbcConfig.java index 2c416828e..20698d566 100644 --- a/micro-jdbc/src/main/java/com/aol/micro/server/spring/datasource/JdbcConfig.java +++ b/micro-jdbc/src/main/java/com/oath/micro/server/spring/datasource/JdbcConfig.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.spring.datasource; +package com.oath.micro.server.spring.datasource; import java.util.Properties; @@ -10,8 +10,8 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; -import com.aol.micro.server.config.ConfigAccessor; -import com.aol.micro.server.utility.UsefulStaticMethods; +import com.oath.micro.server.config.ConfigAccessor; +import com.oath.micro.server.utility.UsefulStaticMethods; @Getter @Builder diff --git a/micro-jdbc/src/main/java/com/aol/micro/server/spring/datasource/jdbc/SQL.java b/micro-jdbc/src/main/java/com/oath/micro/server/spring/datasource/jdbc/SQL.java similarity index 89% rename from micro-jdbc/src/main/java/com/aol/micro/server/spring/datasource/jdbc/SQL.java rename to micro-jdbc/src/main/java/com/oath/micro/server/spring/datasource/jdbc/SQL.java index ac265291d..1776be760 100644 --- a/micro-jdbc/src/main/java/com/aol/micro/server/spring/datasource/jdbc/SQL.java +++ b/micro-jdbc/src/main/java/com/oath/micro/server/spring/datasource/jdbc/SQL.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.spring.datasource.jdbc; +package com.oath.micro.server.spring.datasource.jdbc; import org.springframework.beans.factory.annotation.Qualifier; import javax.sql.DataSource; diff --git a/micro-jdbc/src/main/resources/META-INF/services/com.aol.micro.server.Plugin b/micro-jdbc/src/main/resources/META-INF/services/com.aol.micro.server.Plugin deleted file mode 100644 index 02e59124f..000000000 --- a/micro-jdbc/src/main/resources/META-INF/services/com.aol.micro.server.Plugin +++ /dev/null @@ -1 +0,0 @@ -com.aol.micro.server.spring.JdbcPlugin \ No newline at end of file diff --git a/micro-jdbc/src/main/resources/META-INF/services/com.oath.micro.server.Plugin b/micro-jdbc/src/main/resources/META-INF/services/com.oath.micro.server.Plugin new file mode 100644 index 000000000..34113ee92 --- /dev/null +++ b/micro-jdbc/src/main/resources/META-INF/services/com.oath.micro.server.Plugin @@ -0,0 +1 @@ +com.oath.micro.server.spring.JdbcPlugin \ No newline at end of file diff --git a/micro-jdbc/src/test/java/com/aol/micro/server/JdbcConfigTest.java b/micro-jdbc/src/test/java/com/oath/micro/server/JdbcConfigTest.java similarity index 88% rename from micro-jdbc/src/test/java/com/aol/micro/server/JdbcConfigTest.java rename to micro-jdbc/src/test/java/com/oath/micro/server/JdbcConfigTest.java index dba8f3d52..10d283646 100644 --- a/micro-jdbc/src/test/java/com/aol/micro/server/JdbcConfigTest.java +++ b/micro-jdbc/src/test/java/com/oath/micro/server/JdbcConfigTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server; +package com.oath.micro.server; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; @@ -9,8 +9,8 @@ import org.junit.Before; import org.junit.Test; -import com.aol.micro.server.config.Config; -import com.aol.micro.server.spring.datasource.JdbcConfig; +import com.oath.micro.server.config.Config; +import com.oath.micro.server.spring.datasource.JdbcConfig; public class JdbcConfigTest { diff --git a/micro-jersey/src/main/java/com/aol/micro/server/rest/jersey/ConfigureMainServlet.java b/micro-jersey/src/main/java/com/aol/micro/server/rest/jersey/ConfigureMainServlet.java deleted file mode 100644 index 55b09ba68..000000000 --- a/micro-jersey/src/main/java/com/aol/micro/server/rest/jersey/ConfigureMainServlet.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.aol.micro.server.rest.jersey; - -import java.util.HashMap; - -import org.glassfish.jersey.servlet.ServletContainer; - -import com.aol.micro.server.rest.RestConfiguration; -import com.aol.micro.server.servers.ServerThreadLocalVariables; - -public class ConfigureMainServlet { - public RestConfiguration servletConfig() { - - return new RestConfiguration(new CustomJerseyServlet(ServerThreadLocalVariables.getContext().get()),"Jersey Spring Web Application","jersey.config.server.provider.packages",new HashMap<>()); - - } -} diff --git a/micro-jersey/src/main/java/com/aol/micro/server/rest/jersey/AsyncBinder.java b/micro-jersey/src/main/java/com/oath/micro/server/rest/jersey/AsyncBinder.java similarity index 77% rename from micro-jersey/src/main/java/com/aol/micro/server/rest/jersey/AsyncBinder.java rename to micro-jersey/src/main/java/com/oath/micro/server/rest/jersey/AsyncBinder.java index 24f81513d..9fb40ef0e 100644 --- a/micro-jersey/src/main/java/com/aol/micro/server/rest/jersey/AsyncBinder.java +++ b/micro-jersey/src/main/java/com/oath/micro/server/rest/jersey/AsyncBinder.java @@ -1,8 +1,7 @@ -package com.aol.micro.server.rest.jersey; +package com.oath.micro.server.rest.jersey; import org.glassfish.hk2.utilities.binding.AbstractBinder; import org.glassfish.jersey.server.spi.internal.ResourceMethodDispatcher; -import org.glassfish.jersey.server.spi.internal.ResourceMethodInvocationHandlerProvider; import javax.inject.Singleton; diff --git a/micro-jersey/src/main/java/com/aol/micro/server/rest/jersey/AsyncDispatcher.java b/micro-jersey/src/main/java/com/oath/micro/server/rest/jersey/AsyncDispatcher.java similarity index 95% rename from micro-jersey/src/main/java/com/aol/micro/server/rest/jersey/AsyncDispatcher.java rename to micro-jersey/src/main/java/com/oath/micro/server/rest/jersey/AsyncDispatcher.java index db0cfbc91..eefbb581a 100644 --- a/micro-jersey/src/main/java/com/aol/micro/server/rest/jersey/AsyncDispatcher.java +++ b/micro-jersey/src/main/java/com/oath/micro/server/rest/jersey/AsyncDispatcher.java @@ -1,7 +1,5 @@ -package com.aol.micro.server.rest.jersey; +package com.oath.micro.server.rest.jersey; -import com.oath.cyclops.types.mixins.Printable; -import cyclops.reactive.ReactiveSeq; import cyclops.reactive.Spouts; import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; @@ -11,7 +9,6 @@ import org.glassfish.jersey.server.internal.LocalizationMessages; import org.glassfish.jersey.server.internal.inject.ConfiguredValidator; import org.glassfish.jersey.server.internal.process.AsyncContext; -import javax.inject.Provider; import org.glassfish.jersey.server.model.Invocable; import org.glassfish.jersey.server.spi.internal.ResourceMethodDispatcher; diff --git a/micro-jersey/src/main/java/com/oath/micro/server/rest/jersey/ConfigureMainServlet.java b/micro-jersey/src/main/java/com/oath/micro/server/rest/jersey/ConfigureMainServlet.java new file mode 100644 index 000000000..4d254a5c8 --- /dev/null +++ b/micro-jersey/src/main/java/com/oath/micro/server/rest/jersey/ConfigureMainServlet.java @@ -0,0 +1,14 @@ +package com.oath.micro.server.rest.jersey; + +import java.util.HashMap; + +import com.oath.micro.server.rest.RestConfiguration; +import com.oath.micro.server.servers.ServerThreadLocalVariables; + +public class ConfigureMainServlet { + public RestConfiguration servletConfig() { + + return new RestConfiguration(new CustomJerseyServlet(ServerThreadLocalVariables.getContext().get()),"Jersey Spring Web Application","jersey.config.server.provider.packages",new HashMap<>()); + + } +} diff --git a/micro-jersey/src/main/java/com/aol/micro/server/rest/jersey/CustomJerseyServlet.java b/micro-jersey/src/main/java/com/oath/micro/server/rest/jersey/CustomJerseyServlet.java similarity index 81% rename from micro-jersey/src/main/java/com/aol/micro/server/rest/jersey/CustomJerseyServlet.java rename to micro-jersey/src/main/java/com/oath/micro/server/rest/jersey/CustomJerseyServlet.java index afa4a3300..5e46f31d9 100644 --- a/micro-jersey/src/main/java/com/aol/micro/server/rest/jersey/CustomJerseyServlet.java +++ b/micro-jersey/src/main/java/com/oath/micro/server/rest/jersey/CustomJerseyServlet.java @@ -1,10 +1,10 @@ -package com.aol.micro.server.rest.jersey; +package com.oath.micro.server.rest.jersey; import javax.servlet.ServletException; import org.glassfish.jersey.servlet.ServletContainer; -import com.aol.micro.server.servers.ServerThreadLocalVariables; +import com.oath.micro.server.servers.ServerThreadLocalVariables; public class CustomJerseyServlet extends ServletContainer{ diff --git a/micro-jersey/src/main/java/com/aol/micro/server/rest/jersey/JerseyPlugin.java b/micro-jersey/src/main/java/com/oath/micro/server/rest/jersey/JerseyPlugin.java similarity index 80% rename from micro-jersey/src/main/java/com/aol/micro/server/rest/jersey/JerseyPlugin.java rename to micro-jersey/src/main/java/com/oath/micro/server/rest/jersey/JerseyPlugin.java index b2f67fb57..66ff46729 100644 --- a/micro-jersey/src/main/java/com/aol/micro/server/rest/jersey/JerseyPlugin.java +++ b/micro-jersey/src/main/java/com/oath/micro/server/rest/jersey/JerseyPlugin.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.rest.jersey; +package com.oath.micro.server.rest.jersey; import java.util.Map; import java.util.Optional; @@ -11,14 +11,12 @@ import cyclops.collections.mutable.MapX; import cyclops.collections.mutable.SetX; import cyclops.companion.MapXs; -import cyclops.collections.immutable.PersistentMapX; -import cyclops.collections.immutable.PersistentSetX; import org.glassfish.jersey.CommonProperties; -import com.aol.micro.server.Plugin; -import com.aol.micro.server.rest.RestConfiguration; -import com.aol.micro.server.servers.model.ServerData; +import com.oath.micro.server.Plugin; +import com.oath.micro.server.rest.RestConfiguration; +import com.oath.micro.server.servers.model.ServerData; public class JerseyPlugin implements Plugin{ diff --git a/micro-jersey/src/main/java/com/aol/micro/server/rest/jersey/JerseyRestApplication.java b/micro-jersey/src/main/java/com/oath/micro/server/rest/jersey/JerseyRestApplication.java similarity index 91% rename from micro-jersey/src/main/java/com/aol/micro/server/rest/jersey/JerseyRestApplication.java rename to micro-jersey/src/main/java/com/oath/micro/server/rest/jersey/JerseyRestApplication.java index 4abddd118..55f2135e4 100644 --- a/micro-jersey/src/main/java/com/aol/micro/server/rest/jersey/JerseyRestApplication.java +++ b/micro-jersey/src/main/java/com/oath/micro/server/rest/jersey/JerseyRestApplication.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.rest.jersey; +package com.oath.micro.server.rest.jersey; import java.util.List; import java.util.Map; @@ -12,10 +12,10 @@ import org.glassfish.jersey.server.ResourceConfig; import org.glassfish.jersey.server.ServerProperties; -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.auto.discovery.RestResource; -import com.aol.micro.server.module.JaxRsProvider; -import com.aol.micro.server.servers.ServerThreadLocalVariables; +import com.oath.micro.server.auto.discovery.Rest; +import com.oath.micro.server.auto.discovery.RestResource; +import com.oath.micro.server.module.JaxRsProvider; +import com.oath.micro.server.servers.ServerThreadLocalVariables; public class JerseyRestApplication extends ResourceConfig { diff --git a/micro-jersey/src/main/java/com/aol/micro/server/rest/jersey/JerseySpringIntegrationContextListener.java b/micro-jersey/src/main/java/com/oath/micro/server/rest/jersey/JerseySpringIntegrationContextListener.java similarity index 92% rename from micro-jersey/src/main/java/com/aol/micro/server/rest/jersey/JerseySpringIntegrationContextListener.java rename to micro-jersey/src/main/java/com/oath/micro/server/rest/jersey/JerseySpringIntegrationContextListener.java index 9e6e05c8e..3a7a229a5 100644 --- a/micro-jersey/src/main/java/com/aol/micro/server/rest/jersey/JerseySpringIntegrationContextListener.java +++ b/micro-jersey/src/main/java/com/oath/micro/server/rest/jersey/JerseySpringIntegrationContextListener.java @@ -1,9 +1,9 @@ -package com.aol.micro.server.rest.jersey; +package com.oath.micro.server.rest.jersey; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; -import com.aol.micro.server.servers.model.ServerData; +import com.oath.micro.server.servers.model.ServerData; import cyclops.collections.mutable.ListX; public class JerseySpringIntegrationContextListener implements ServletContextListener { diff --git a/micro-jersey/src/main/resources/META-INF/services/com.aol.micro.server.Plugin b/micro-jersey/src/main/resources/META-INF/services/com.aol.micro.server.Plugin deleted file mode 100644 index 1c8614375..000000000 --- a/micro-jersey/src/main/resources/META-INF/services/com.aol.micro.server.Plugin +++ /dev/null @@ -1 +0,0 @@ -com.aol.micro.server.rest.jersey.JerseyPlugin \ No newline at end of file diff --git a/micro-jersey/src/main/resources/META-INF/services/com.oath.micro.server.Plugin b/micro-jersey/src/main/resources/META-INF/services/com.oath.micro.server.Plugin new file mode 100644 index 000000000..2416a38a5 --- /dev/null +++ b/micro-jersey/src/main/resources/META-INF/services/com.oath.micro.server.Plugin @@ -0,0 +1 @@ +com.oath.micro.server.rest.jersey.JerseyPlugin \ No newline at end of file diff --git a/micro-jersey/src/test/java/com/aol/micro/server/rest/jersey/RestContextListenerTest.java b/micro-jersey/src/test/java/com/aol/micro/server/rest/jersey/RestContextListenerTest.java deleted file mode 100644 index 70a13ee81..000000000 --- a/micro-jersey/src/test/java/com/aol/micro/server/rest/jersey/RestContextListenerTest.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.aol.micro.server.rest.jersey; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.Arrays; - -import org.junit.Before; -import org.junit.Test; - - -import com.aol.micro.server.rest.jersey.JerseyRestApplication; -import com.aol.micro.server.rest.jersey.JerseySpringIntegrationContextListener; -import com.aol.micro.server.servers.model.ServerData; - -public class RestContextListenerTest { - - private JerseySpringIntegrationContextListener restContextListener; - private ServletStatusResource statsResource; - - @Before - public void setUp() { - statsResource = new ServletStatusResource(); - ServerData serverData = new ServerData(8080, Arrays.asList(statsResource), null, "baseUrl", () -> "test"); - restContextListener = new JerseySpringIntegrationContextListener(serverData); - } - - @Test - public void testContextInitialized() { - restContextListener.contextInitialized(null); - assertThat(JerseyRestApplication.getResourcesMap().get("test").get(0), is(statsResource)); - } - - @Test - public void testContextDestroyed() { - restContextListener.contextDestroyed(null); - } - -} diff --git a/micro-jersey/src/test/java/com/aol/micro/server/rest/jersey/ServletStatusResource.java b/micro-jersey/src/test/java/com/aol/micro/server/rest/jersey/ServletStatusResource.java deleted file mode 100644 index 5c8cf972e..000000000 --- a/micro-jersey/src/test/java/com/aol/micro/server/rest/jersey/ServletStatusResource.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.aol.micro.server.rest.jersey; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.RestResource; - -@Component -@Path("/servlet") -public class ServletStatusResource implements RestResource { - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "ok"; - } - -} \ No newline at end of file diff --git a/micro-jersey/src/test/java/com/aol/micro/server/rest/jersey/JerseyRestApplicationTest.java b/micro-jersey/src/test/java/com/oath/micro/server/rest/jersey/JerseyRestApplicationTest.java similarity index 84% rename from micro-jersey/src/test/java/com/aol/micro/server/rest/jersey/JerseyRestApplicationTest.java rename to micro-jersey/src/test/java/com/oath/micro/server/rest/jersey/JerseyRestApplicationTest.java index 31e45ab05..b26163e0c 100644 --- a/micro-jersey/src/test/java/com/aol/micro/server/rest/jersey/JerseyRestApplicationTest.java +++ b/micro-jersey/src/test/java/com/oath/micro/server/rest/jersey/JerseyRestApplicationTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.rest.jersey; +package com.oath.micro.server.rest.jersey; import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.is; @@ -14,8 +14,8 @@ import org.junit.Ignore; import org.junit.Test; -import com.aol.micro.server.rest.jackson.JacksonFeature; -import com.aol.micro.server.servers.ServerThreadLocalVariables; +import com.oath.micro.server.rest.jackson.JacksonFeature; +import com.oath.micro.server.servers.ServerThreadLocalVariables; public class JerseyRestApplicationTest { @@ -32,7 +32,7 @@ public void setup(){ public void testDefaultConstructor() { JerseyRestApplication app = new JerseyRestApplication(); assertTrue(app.isRegistered(ServletStatusResource.class)); - assertThat( app.getApplication().getClasses().stream().map(c -> c.getName()).collect(Collectors.toSet()),hasItem("com.aol.micro.server.rest.jackson.JacksonFeature".intern())); + assertThat( app.getApplication().getClasses().stream().map(c -> c.getName()).collect(Collectors.toSet()),hasItem("com.oath.micro.server.rest.jackson.JacksonFeature".intern())); } @@ -41,7 +41,7 @@ public void testDefaultConstructorCleared() { JerseyRestApplication.getResourcesMap().clear(); ServerThreadLocalVariables.getContext().set(Thread.currentThread().getName()); JerseyRestApplication app = new JerseyRestApplication(); - assertThat(app.getApplication().getClasses().stream().map(c -> c.getName()).collect(Collectors.toSet()),hasItem("com.aol.micro.server.rest.jackson.JacksonFeature")); + assertThat(app.getApplication().getClasses().stream().map(c -> c.getName()).collect(Collectors.toSet()),hasItem("com.oath.micro.server.rest.jackson.JacksonFeature")); assertFalse(app.isRegistered(ServletStatusResource.class)); } diff --git a/micro-jersey/src/test/java/com/aol/micro/server/rest/jersey/JerseySpringIntegrationContextListenerTest.java b/micro-jersey/src/test/java/com/oath/micro/server/rest/jersey/JerseySpringIntegrationContextListenerTest.java similarity index 91% rename from micro-jersey/src/test/java/com/aol/micro/server/rest/jersey/JerseySpringIntegrationContextListenerTest.java rename to micro-jersey/src/test/java/com/oath/micro/server/rest/jersey/JerseySpringIntegrationContextListenerTest.java index 8456e897b..bc7e37250 100644 --- a/micro-jersey/src/test/java/com/aol/micro/server/rest/jersey/JerseySpringIntegrationContextListenerTest.java +++ b/micro-jersey/src/test/java/com/oath/micro/server/rest/jersey/JerseySpringIntegrationContextListenerTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.rest.jersey; +package com.oath.micro.server.rest.jersey; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; @@ -10,7 +10,7 @@ import org.junit.Before; import org.junit.Test; -import com.aol.micro.server.servers.model.ServerData; +import com.oath.micro.server.servers.model.ServerData; public class JerseySpringIntegrationContextListenerTest { diff --git a/micro-jersey/src/test/java/com/oath/micro/server/rest/jersey/RestContextListenerTest.java b/micro-jersey/src/test/java/com/oath/micro/server/rest/jersey/RestContextListenerTest.java new file mode 100644 index 000000000..a958e1090 --- /dev/null +++ b/micro-jersey/src/test/java/com/oath/micro/server/rest/jersey/RestContextListenerTest.java @@ -0,0 +1,37 @@ +package com.oath.micro.server.rest.jersey; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.Arrays; + +import org.junit.Before; +import org.junit.Test; + + +import com.oath.micro.server.servers.model.ServerData; + +public class RestContextListenerTest { + + private JerseySpringIntegrationContextListener restContextListener; + private ServletStatusResource statsResource; + + @Before + public void setUp() { + statsResource = new ServletStatusResource(); + ServerData serverData = new ServerData(8080, Arrays.asList(statsResource), null, "baseUrl", () -> "test"); + restContextListener = new JerseySpringIntegrationContextListener(serverData); + } + + @Test + public void testContextInitialized() { + restContextListener.contextInitialized(null); + assertThat(JerseyRestApplication.getResourcesMap().get("test").get(0), is(statsResource)); + } + + @Test + public void testContextDestroyed() { + restContextListener.contextDestroyed(null); + } + +} diff --git a/micro-jersey/src/test/java/com/oath/micro/server/rest/jersey/ServletStatusResource.java b/micro-jersey/src/test/java/com/oath/micro/server/rest/jersey/ServletStatusResource.java new file mode 100644 index 000000000..b1f22ef75 --- /dev/null +++ b/micro-jersey/src/test/java/com/oath/micro/server/rest/jersey/ServletStatusResource.java @@ -0,0 +1,22 @@ +package com.oath.micro.server.rest.jersey; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.RestResource; + +@Component +@Path("/servlet") +public class ServletStatusResource implements RestResource { + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "ok"; + } + +} \ No newline at end of file diff --git a/micro-jmx-metrics/src/main/java/com/aol/micro/server/application/metrics/jmx/JmxMetricsPlugin.java b/micro-jmx-metrics/src/main/java/com/aol/micro/server/application/metrics/jmx/JmxMetricsPlugin.java deleted file mode 100644 index 382a270de..000000000 --- a/micro-jmx-metrics/src/main/java/com/aol/micro/server/application/metrics/jmx/JmxMetricsPlugin.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.aol.micro.server.application.metrics.jmx; - -import com.aol.micro.server.Plugin; -import cyclops.collections.immutable.PersistentSetX; -import cyclops.collections.mutable.SetX; - -import java.util.Set; - -public class JmxMetricsPlugin implements Plugin { - - @Override - public Set springClasses() { - return SetX.of(JmxMetricsAcquirer.class); - } - -} diff --git a/micro-jmx-metrics/src/main/java/com/aol/micro/server/application/metrics/jmx/JmxMetricsAcquirer.java b/micro-jmx-metrics/src/main/java/com/oath/micro/server/application/metrics/jmx/JmxMetricsAcquirer.java similarity index 99% rename from micro-jmx-metrics/src/main/java/com/aol/micro/server/application/metrics/jmx/JmxMetricsAcquirer.java rename to micro-jmx-metrics/src/main/java/com/oath/micro/server/application/metrics/jmx/JmxMetricsAcquirer.java index 8d5285b5d..7e7733d45 100644 --- a/micro-jmx-metrics/src/main/java/com/aol/micro/server/application/metrics/jmx/JmxMetricsAcquirer.java +++ b/micro-jmx-metrics/src/main/java/com/oath/micro/server/application/metrics/jmx/JmxMetricsAcquirer.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.application.metrics.jmx; +package com.oath.micro.server.application.metrics.jmx; import java.lang.management.ManagementFactory; import java.util.Arrays; diff --git a/micro-jmx-metrics/src/main/java/com/oath/micro/server/application/metrics/jmx/JmxMetricsPlugin.java b/micro-jmx-metrics/src/main/java/com/oath/micro/server/application/metrics/jmx/JmxMetricsPlugin.java new file mode 100644 index 000000000..25df3008b --- /dev/null +++ b/micro-jmx-metrics/src/main/java/com/oath/micro/server/application/metrics/jmx/JmxMetricsPlugin.java @@ -0,0 +1,15 @@ +package com.oath.micro.server.application.metrics.jmx; + +import com.oath.micro.server.Plugin; +import cyclops.collections.mutable.SetX; + +import java.util.Set; + +public class JmxMetricsPlugin implements Plugin { + + @Override + public Set springClasses() { + return SetX.of(JmxMetricsAcquirer.class); + } + +} diff --git a/micro-jmx-metrics/src/main/resources/META-INF/services/com.aol.micro.server.Plugin b/micro-jmx-metrics/src/main/resources/META-INF/services/com.aol.micro.server.Plugin deleted file mode 100644 index 1c56ec949..000000000 --- a/micro-jmx-metrics/src/main/resources/META-INF/services/com.aol.micro.server.Plugin +++ /dev/null @@ -1 +0,0 @@ -com.aol.micro.server.application.metrics.jmx.JmxMetricsPlugin diff --git a/micro-jmx-metrics/src/main/resources/META-INF/services/com.oath.micro.server.Plugin b/micro-jmx-metrics/src/main/resources/META-INF/services/com.oath.micro.server.Plugin new file mode 100644 index 000000000..395e4f80a --- /dev/null +++ b/micro-jmx-metrics/src/main/resources/META-INF/services/com.oath.micro.server.Plugin @@ -0,0 +1 @@ +com.oath.micro.server.application.metrics.jmx.JmxMetricsPlugin diff --git a/micro-jmx-metrics/src/test/java/com/aol/micro/server/application/metrics/jmx/JmxMetricsAcquirerTest.java b/micro-jmx-metrics/src/test/java/com/oath/micro/server/application/metrics/jmx/JmxMetricsAcquirerTest.java similarity index 93% rename from micro-jmx-metrics/src/test/java/com/aol/micro/server/application/metrics/jmx/JmxMetricsAcquirerTest.java rename to micro-jmx-metrics/src/test/java/com/oath/micro/server/application/metrics/jmx/JmxMetricsAcquirerTest.java index 077fdc351..0d7ae5990 100644 --- a/micro-jmx-metrics/src/test/java/com/aol/micro/server/application/metrics/jmx/JmxMetricsAcquirerTest.java +++ b/micro-jmx-metrics/src/test/java/com/oath/micro/server/application/metrics/jmx/JmxMetricsAcquirerTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.application.metrics.jmx; +package com.oath.micro.server.application.metrics.jmx; import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; diff --git a/micro-log-streamer/src/main/java/com/aol/micro/server/log/LogLookup.java b/micro-log-streamer/src/main/java/com/aol/micro/server/log/LogLookup.java deleted file mode 100644 index 7495bf13d..000000000 --- a/micro-log-streamer/src/main/java/com/aol/micro/server/log/LogLookup.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.aol.micro.server.log; - -import java.io.File; - -public interface LogLookup { - - public File lookup(String alias); -} diff --git a/micro-log-streamer/src/main/java/com/aol/micro/server/log/LogTailerPlugin.java b/micro-log-streamer/src/main/java/com/aol/micro/server/log/LogTailerPlugin.java deleted file mode 100644 index dabd68dc2..000000000 --- a/micro-log-streamer/src/main/java/com/aol/micro/server/log/LogTailerPlugin.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.aol.micro.server.log; - - -import com.aol.micro.server.Plugin; -import com.aol.micro.server.log.rest.LogStreamer; -import cyclops.collections.immutable.PersistentSetX; -import cyclops.collections.mutable.SetX; - -import java.util.Set; - -public class LogTailerPlugin implements Plugin { - - @Override - public Set springClasses() { - return SetX.of(LogTailer.class, LogStreamer.class); - } - -} diff --git a/micro-log-streamer/src/main/java/com/oath/micro/server/log/LogLookup.java b/micro-log-streamer/src/main/java/com/oath/micro/server/log/LogLookup.java new file mode 100644 index 000000000..70891c4cf --- /dev/null +++ b/micro-log-streamer/src/main/java/com/oath/micro/server/log/LogLookup.java @@ -0,0 +1,8 @@ +package com.oath.micro.server.log; + +import java.io.File; + +public interface LogLookup { + + public File lookup(String alias); +} diff --git a/micro-log-streamer/src/main/java/com/aol/micro/server/log/LogTailer.java b/micro-log-streamer/src/main/java/com/oath/micro/server/log/LogTailer.java similarity index 97% rename from micro-log-streamer/src/main/java/com/aol/micro/server/log/LogTailer.java rename to micro-log-streamer/src/main/java/com/oath/micro/server/log/LogTailer.java index f8a6162a5..a2444bacc 100644 --- a/micro-log-streamer/src/main/java/com/aol/micro/server/log/LogTailer.java +++ b/micro-log-streamer/src/main/java/com/oath/micro/server/log/LogTailer.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.log; +package com.oath.micro.server.log; import java.io.File; import java.util.Optional; diff --git a/micro-log-streamer/src/main/java/com/oath/micro/server/log/LogTailerPlugin.java b/micro-log-streamer/src/main/java/com/oath/micro/server/log/LogTailerPlugin.java new file mode 100644 index 000000000..54ed2314e --- /dev/null +++ b/micro-log-streamer/src/main/java/com/oath/micro/server/log/LogTailerPlugin.java @@ -0,0 +1,17 @@ +package com.oath.micro.server.log; + + +import com.oath.micro.server.Plugin; +import com.oath.micro.server.log.rest.LogStreamer; +import cyclops.collections.mutable.SetX; + +import java.util.Set; + +public class LogTailerPlugin implements Plugin { + + @Override + public Set springClasses() { + return SetX.of(LogTailer.class, LogStreamer.class); + } + +} diff --git a/micro-log-streamer/src/main/java/com/aol/micro/server/log/rest/LogStreamer.java b/micro-log-streamer/src/main/java/com/oath/micro/server/log/rest/LogStreamer.java similarity index 94% rename from micro-log-streamer/src/main/java/com/aol/micro/server/log/rest/LogStreamer.java rename to micro-log-streamer/src/main/java/com/oath/micro/server/log/rest/LogStreamer.java index 9d9b30b1b..dc1867def 100644 --- a/micro-log-streamer/src/main/java/com/aol/micro/server/log/rest/LogStreamer.java +++ b/micro-log-streamer/src/main/java/com/oath/micro/server/log/rest/LogStreamer.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.log.rest; +package com.oath.micro.server.log.rest; import java.io.BufferedWriter; import java.io.IOException; @@ -19,9 +19,9 @@ import org.apache.commons.io.input.TailerListener; import org.springframework.stereotype.Component; -import com.aol.micro.server.auto.discovery.CommonRestResource; -import com.aol.micro.server.auto.discovery.SingletonRestResource; -import com.aol.micro.server.log.LogTailer; +import com.oath.micro.server.auto.discovery.CommonRestResource; +import com.oath.micro.server.auto.discovery.SingletonRestResource; +import com.oath.micro.server.log.LogTailer; import lombok.AllArgsConstructor; diff --git a/micro-log-streamer/src/main/resources/META-INF/services/com.aol.micro.server.Plugin b/micro-log-streamer/src/main/resources/META-INF/services/com.aol.micro.server.Plugin deleted file mode 100644 index a015985da..000000000 --- a/micro-log-streamer/src/main/resources/META-INF/services/com.aol.micro.server.Plugin +++ /dev/null @@ -1 +0,0 @@ -com.aol.micro.server.log.LogTailerPlugin \ No newline at end of file diff --git a/micro-log-streamer/src/main/resources/META-INF/services/com.oath.micro.server.Plugin b/micro-log-streamer/src/main/resources/META-INF/services/com.oath.micro.server.Plugin new file mode 100644 index 000000000..fa28aa4a4 --- /dev/null +++ b/micro-log-streamer/src/main/resources/META-INF/services/com.oath.micro.server.Plugin @@ -0,0 +1 @@ +com.oath.micro.server.log.LogTailerPlugin \ No newline at end of file diff --git a/micro-log-streamer/src/test/java/app/com/aol/micro/server/log/LogTest.java b/micro-log-streamer/src/test/java/app/com/oath/micro/server/log/LogTest.java similarity index 83% rename from micro-log-streamer/src/test/java/app/com/aol/micro/server/log/LogTest.java rename to micro-log-streamer/src/test/java/app/com/oath/micro/server/log/LogTest.java index d06cbd68e..4c9d57c98 100644 --- a/micro-log-streamer/src/test/java/app/com/aol/micro/server/log/LogTest.java +++ b/micro-log-streamer/src/test/java/app/com/oath/micro/server/log/LogTest.java @@ -1,4 +1,4 @@ -package app.com.aol.micro.server.log; +package app.com.oath.micro.server.log; import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertThat; @@ -7,19 +7,16 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -import javax.annotation.PostConstruct; - import org.apache.commons.io.FileUtils; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.RestResource; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.reactive.rest.ReactiveRequest; -import com.aol.micro.server.testing.RestAgent; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.auto.discovery.RestResource; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.reactive.rest.ReactiveRequest; +import com.oath.micro.server.testing.RestAgent; @Microserver(properties = { "log.tailer.file.location", "/tmp/tailer-test-file" }) public class LogTest implements RestResource { diff --git a/micro-log-streamer/src/test/java/app/com/aol/micro/server/log/alias/CustomAlias.java b/micro-log-streamer/src/test/java/app/com/oath/micro/server/log/alias/CustomAlias.java similarity index 84% rename from micro-log-streamer/src/test/java/app/com/aol/micro/server/log/alias/CustomAlias.java rename to micro-log-streamer/src/test/java/app/com/oath/micro/server/log/alias/CustomAlias.java index 4693f1db2..07ef7d5ed 100644 --- a/micro-log-streamer/src/test/java/app/com/aol/micro/server/log/alias/CustomAlias.java +++ b/micro-log-streamer/src/test/java/app/com/oath/micro/server/log/alias/CustomAlias.java @@ -1,4 +1,4 @@ -package app.com.aol.micro.server.log.alias; +package app.com.oath.micro.server.log.alias; import java.io.File; import java.util.HashMap; @@ -6,7 +6,7 @@ import org.springframework.stereotype.Component; -import com.aol.micro.server.log.LogLookup; +import com.oath.micro.server.log.LogLookup; @Component public class CustomAlias implements LogLookup { diff --git a/micro-log-streamer/src/test/java/app/com/aol/micro/server/log/alias/CustomAliasLogTest.java b/micro-log-streamer/src/test/java/app/com/oath/micro/server/log/alias/CustomAliasLogTest.java similarity index 83% rename from micro-log-streamer/src/test/java/app/com/aol/micro/server/log/alias/CustomAliasLogTest.java rename to micro-log-streamer/src/test/java/app/com/oath/micro/server/log/alias/CustomAliasLogTest.java index 26a4850a6..98784d26e 100644 --- a/micro-log-streamer/src/test/java/app/com/aol/micro/server/log/alias/CustomAliasLogTest.java +++ b/micro-log-streamer/src/test/java/app/com/oath/micro/server/log/alias/CustomAliasLogTest.java @@ -1,4 +1,4 @@ -package app.com.aol.micro.server.log.alias; +package app.com.oath.micro.server.log.alias; import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertThat; @@ -7,19 +7,16 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -import javax.annotation.PostConstruct; - import org.apache.commons.io.FileUtils; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.RestResource; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.reactive.rest.ReactiveRequest; -import com.aol.micro.server.testing.RestAgent; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.auto.discovery.RestResource; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.reactive.rest.ReactiveRequest; +import com.oath.micro.server.testing.RestAgent; @Microserver(properties = { "log.tailer.file.location", "/tmp/tailer-test-file" }) public class CustomAliasLogTest implements RestResource { diff --git a/micro-log-streamer/src/test/java/com/aol/micro/server/testing/RestAgent.java b/micro-log-streamer/src/test/java/com/aol/micro/server/testing/RestAgent.java deleted file mode 100644 index ce204f810..000000000 --- a/micro-log-streamer/src/test/java/com/aol/micro/server/testing/RestAgent.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.aol.micro.server.testing; - -import java.util.List; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.Invocation.Builder; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; - -import com.aol.micro.server.rest.jackson.JacksonUtil; - -public class RestAgent { - - - public String getJson(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.get(String.class); - - } - - public String get(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.TEXT_PLAIN); - - return request.get(String.class); - - } - - public T post(String url, Object payload,Class type) { - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); - } - - -} diff --git a/micro-log-streamer/src/test/java/com/oath/micro/server/testing/RestAgent.java b/micro-log-streamer/src/test/java/com/oath/micro/server/testing/RestAgent.java new file mode 100644 index 000000000..b2b86303e --- /dev/null +++ b/micro-log-streamer/src/test/java/com/oath/micro/server/testing/RestAgent.java @@ -0,0 +1,53 @@ +package com.oath.micro.server.testing; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.Invocation.Builder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; + +import com.oath.micro.server.rest.jackson.JacksonUtil; + +public class RestAgent { + + + public String getJson(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.get(String.class); + + } + + public String get(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.TEXT_PLAIN); + + return request.get(String.class); + + } + + public T post(String url, Object payload,Class type) { + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); + } + + +} diff --git a/micro-log4j/src/main/java/com/aol/micro/server/log4j/Log4jPlugin.java b/micro-log4j/src/main/java/com/aol/micro/server/log4j/Log4jPlugin.java deleted file mode 100644 index 3eb9897e4..000000000 --- a/micro-log4j/src/main/java/com/aol/micro/server/log4j/Log4jPlugin.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.aol.micro.server.log4j; - - -import com.aol.micro.server.Plugin; -import com.aol.micro.server.log4j.rest.Log4jLoggerResource; -import com.aol.micro.server.log4j.rest.Log4jRootLoggerResource; -import com.aol.micro.server.log4j.service.Log4jRootLoggerChecker; -import cyclops.collections.immutable.PersistentSetX; -import cyclops.collections.mutable.SetX; - -import java.util.Set; - -/** - * - * @author Ke Wang - * - */ -public class Log4jPlugin implements Plugin { - @Override - public Set springClasses() { - return SetX.of(Log4jRootLoggerResource.class, Log4jLoggerResource.class, Log4jRootLoggerChecker.class); - } - -} diff --git a/micro-log4j/src/main/java/com/oath/micro/server/log4j/Log4jPlugin.java b/micro-log4j/src/main/java/com/oath/micro/server/log4j/Log4jPlugin.java new file mode 100644 index 000000000..67a956d1d --- /dev/null +++ b/micro-log4j/src/main/java/com/oath/micro/server/log4j/Log4jPlugin.java @@ -0,0 +1,23 @@ +package com.oath.micro.server.log4j; + + +import com.oath.micro.server.Plugin; +import com.oath.micro.server.log4j.rest.Log4jLoggerResource; +import com.oath.micro.server.log4j.rest.Log4jRootLoggerResource; +import com.oath.micro.server.log4j.service.Log4jRootLoggerChecker; +import cyclops.collections.mutable.SetX; + +import java.util.Set; + +/** + * + * @author Ke Wang + * + */ +public class Log4jPlugin implements Plugin { + @Override + public Set springClasses() { + return SetX.of(Log4jRootLoggerResource.class, Log4jLoggerResource.class, Log4jRootLoggerChecker.class); + } + +} diff --git a/micro-log4j/src/main/java/com/aol/micro/server/log4j/rest/Log4jLoggerResource.java b/micro-log4j/src/main/java/com/oath/micro/server/log4j/rest/Log4jLoggerResource.java similarity index 95% rename from micro-log4j/src/main/java/com/aol/micro/server/log4j/rest/Log4jLoggerResource.java rename to micro-log4j/src/main/java/com/oath/micro/server/log4j/rest/Log4jLoggerResource.java index b2920cedb..0839cf591 100644 --- a/micro-log4j/src/main/java/com/aol/micro/server/log4j/rest/Log4jLoggerResource.java +++ b/micro-log4j/src/main/java/com/oath/micro/server/log4j/rest/Log4jLoggerResource.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.log4j.rest; +package com.oath.micro.server.log4j.rest; import javax.ws.rs.GET; import javax.ws.rs.Path; @@ -10,7 +10,7 @@ import org.apache.log4j.Logger; import org.springframework.stereotype.Component; -import com.aol.micro.server.auto.discovery.SingletonRestResource; +import com.oath.micro.server.auto.discovery.SingletonRestResource; @Component @Path("/log4j/logger") diff --git a/micro-log4j/src/main/java/com/aol/micro/server/log4j/rest/Log4jRootLoggerResource.java b/micro-log4j/src/main/java/com/oath/micro/server/log4j/rest/Log4jRootLoggerResource.java similarity index 92% rename from micro-log4j/src/main/java/com/aol/micro/server/log4j/rest/Log4jRootLoggerResource.java rename to micro-log4j/src/main/java/com/oath/micro/server/log4j/rest/Log4jRootLoggerResource.java index 6f666b14a..fb3803be7 100644 --- a/micro-log4j/src/main/java/com/aol/micro/server/log4j/rest/Log4jRootLoggerResource.java +++ b/micro-log4j/src/main/java/com/oath/micro/server/log4j/rest/Log4jRootLoggerResource.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.log4j.rest; +package com.oath.micro.server.log4j.rest; import javax.ws.rs.GET; import javax.ws.rs.Path; @@ -6,14 +6,13 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; -import org.apache.log4j.BasicConfigurator; import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import com.aol.micro.server.auto.discovery.SingletonRestResource; -import com.aol.micro.server.log4j.service.Log4jRootLoggerChecker; +import com.oath.micro.server.auto.discovery.SingletonRestResource; +import com.oath.micro.server.log4j.service.Log4jRootLoggerChecker; @Component @Path("/log4j/rootlogger") diff --git a/micro-log4j/src/main/java/com/aol/micro/server/log4j/service/Log4jRootLoggerChecker.java b/micro-log4j/src/main/java/com/oath/micro/server/log4j/service/Log4jRootLoggerChecker.java similarity index 96% rename from micro-log4j/src/main/java/com/aol/micro/server/log4j/service/Log4jRootLoggerChecker.java rename to micro-log4j/src/main/java/com/oath/micro/server/log4j/service/Log4jRootLoggerChecker.java index f6cd4711d..db9faee36 100644 --- a/micro-log4j/src/main/java/com/aol/micro/server/log4j/service/Log4jRootLoggerChecker.java +++ b/micro-log4j/src/main/java/com/oath/micro/server/log4j/service/Log4jRootLoggerChecker.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.log4j.service; +package com.oath.micro.server.log4j.service; import lombok.Getter; import lombok.Setter; diff --git a/micro-log4j/src/main/resources/META-INF/services/com.aol.micro.server.Plugin b/micro-log4j/src/main/resources/META-INF/services/com.aol.micro.server.Plugin deleted file mode 100644 index 32bf35904..000000000 --- a/micro-log4j/src/main/resources/META-INF/services/com.aol.micro.server.Plugin +++ /dev/null @@ -1 +0,0 @@ -com.aol.micro.server.log4j.Log4jPlugin diff --git a/micro-log4j/src/main/resources/META-INF/services/com.oath.micro.server.Plugin b/micro-log4j/src/main/resources/META-INF/services/com.oath.micro.server.Plugin new file mode 100644 index 000000000..a3cd47304 --- /dev/null +++ b/micro-log4j/src/main/resources/META-INF/services/com.oath.micro.server.Plugin @@ -0,0 +1 @@ +com.oath.micro.server.log4j.Log4jPlugin diff --git a/micro-log4j/src/test/java/app/level/checker/Log4jRootLoggerChekerRunnerTest.java b/micro-log4j/src/test/java/app/level/checker/Log4jRootLoggerChekerRunnerTest.java index 8709ec724..c3ac02426 100644 --- a/micro-log4j/src/test/java/app/level/checker/Log4jRootLoggerChekerRunnerTest.java +++ b/micro-log4j/src/test/java/app/level/checker/Log4jRootLoggerChekerRunnerTest.java @@ -7,9 +7,9 @@ import org.junit.Before; import org.junit.Test; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.testing.RestAgent; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.testing.RestAgent; @Microserver(properties = { "log4j.root.logger.checker.fixed.rate", "1500" }) public class Log4jRootLoggerChekerRunnerTest { diff --git a/micro-log4j/src/test/java/app/level/setter/Log4jRootLoggerRunnerTest.java b/micro-log4j/src/test/java/app/level/setter/Log4jRootLoggerRunnerTest.java index 6ab10be4b..77939815b 100644 --- a/micro-log4j/src/test/java/app/level/setter/Log4jRootLoggerRunnerTest.java +++ b/micro-log4j/src/test/java/app/level/setter/Log4jRootLoggerRunnerTest.java @@ -7,9 +7,9 @@ import org.junit.Before; import org.junit.Test; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.testing.RestAgent; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.testing.RestAgent; @Microserver(properties = { "log4j.root.logger.checker.active", "false" }) public class Log4jRootLoggerRunnerTest { diff --git a/micro-log4j/src/test/java/com/aol/micro/server/testing/RestAgent.java b/micro-log4j/src/test/java/com/aol/micro/server/testing/RestAgent.java deleted file mode 100644 index 0f68164b7..000000000 --- a/micro-log4j/src/test/java/com/aol/micro/server/testing/RestAgent.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.aol.micro.server.testing; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.Invocation.Builder; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; - -import com.aol.micro.server.rest.jackson.JacksonUtil; - -public class RestAgent { - - - public String getJson(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.get(String.class); - - } - - public String get(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.TEXT_PLAIN); - - return request.get(String.class); - - } - - public T post(String url, Object payload,Class type) { - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); - } - - -} diff --git a/micro-log4j/src/test/java/com/aol/micro/server/log4j/rest/Log4jLoggerResourceTest.java b/micro-log4j/src/test/java/com/oath/micro/server/log4j/rest/Log4jLoggerResourceTest.java similarity index 96% rename from micro-log4j/src/test/java/com/aol/micro/server/log4j/rest/Log4jLoggerResourceTest.java rename to micro-log4j/src/test/java/com/oath/micro/server/log4j/rest/Log4jLoggerResourceTest.java index 7a7da578d..a3230ba92 100644 --- a/micro-log4j/src/test/java/com/aol/micro/server/log4j/rest/Log4jLoggerResourceTest.java +++ b/micro-log4j/src/test/java/com/oath/micro/server/log4j/rest/Log4jLoggerResourceTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.log4j.rest; +package com.oath.micro.server.log4j.rest; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; diff --git a/micro-log4j/src/test/java/com/aol/micro/server/log4j/rest/Log4jLoggerRunnerTest.java b/micro-log4j/src/test/java/com/oath/micro/server/log4j/rest/Log4jLoggerRunnerTest.java similarity index 76% rename from micro-log4j/src/test/java/com/aol/micro/server/log4j/rest/Log4jLoggerRunnerTest.java rename to micro-log4j/src/test/java/com/oath/micro/server/log4j/rest/Log4jLoggerRunnerTest.java index 7d9c0c452..776de5fe9 100644 --- a/micro-log4j/src/test/java/com/aol/micro/server/log4j/rest/Log4jLoggerRunnerTest.java +++ b/micro-log4j/src/test/java/com/oath/micro/server/log4j/rest/Log4jLoggerRunnerTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.log4j.rest; +package com.oath.micro.server.log4j.rest; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; @@ -7,9 +7,9 @@ import org.junit.Before; import org.junit.Test; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.testing.RestAgent; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.testing.RestAgent; @Microserver public class Log4jLoggerRunnerTest { diff --git a/micro-log4j/src/test/java/com/aol/micro/server/log4j/rest/Log4jRootLoggerResourceTest.java b/micro-log4j/src/test/java/com/oath/micro/server/log4j/rest/Log4jRootLoggerResourceTest.java similarity index 96% rename from micro-log4j/src/test/java/com/aol/micro/server/log4j/rest/Log4jRootLoggerResourceTest.java rename to micro-log4j/src/test/java/com/oath/micro/server/log4j/rest/Log4jRootLoggerResourceTest.java index 45538ff2a..f9c0156b9 100644 --- a/micro-log4j/src/test/java/com/aol/micro/server/log4j/rest/Log4jRootLoggerResourceTest.java +++ b/micro-log4j/src/test/java/com/oath/micro/server/log4j/rest/Log4jRootLoggerResourceTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.log4j.rest; +package com.oath.micro.server.log4j.rest; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; diff --git a/micro-log4j/src/test/java/com/aol/micro/server/logback/service/Log4jRootLoggerCheckerTest.java b/micro-log4j/src/test/java/com/oath/micro/server/logback/service/Log4jRootLoggerCheckerTest.java similarity index 87% rename from micro-log4j/src/test/java/com/aol/micro/server/logback/service/Log4jRootLoggerCheckerTest.java rename to micro-log4j/src/test/java/com/oath/micro/server/logback/service/Log4jRootLoggerCheckerTest.java index 96f683ed6..e3022263c 100644 --- a/micro-log4j/src/test/java/com/aol/micro/server/logback/service/Log4jRootLoggerCheckerTest.java +++ b/micro-log4j/src/test/java/com/oath/micro/server/logback/service/Log4jRootLoggerCheckerTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.logback.service; +package com.oath.micro.server.logback.service; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; @@ -8,7 +8,7 @@ import org.junit.Before; import org.junit.Test; -import com.aol.micro.server.log4j.service.Log4jRootLoggerChecker; +import com.oath.micro.server.log4j.service.Log4jRootLoggerChecker; diff --git a/micro-log4j/src/test/java/com/oath/micro/server/testing/RestAgent.java b/micro-log4j/src/test/java/com/oath/micro/server/testing/RestAgent.java new file mode 100644 index 000000000..b2b86303e --- /dev/null +++ b/micro-log4j/src/test/java/com/oath/micro/server/testing/RestAgent.java @@ -0,0 +1,53 @@ +package com.oath.micro.server.testing; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.Invocation.Builder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; + +import com.oath.micro.server.rest.jackson.JacksonUtil; + +public class RestAgent { + + + public String getJson(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.get(String.class); + + } + + public String get(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.TEXT_PLAIN); + + return request.get(String.class); + + } + + public T post(String url, Object payload,Class type) { + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); + } + + +} diff --git a/micro-logback/src/main/java/com/aol/micro/server/logback/LogbackPlugin.java b/micro-logback/src/main/java/com/aol/micro/server/logback/LogbackPlugin.java deleted file mode 100644 index 3dff182ca..000000000 --- a/micro-logback/src/main/java/com/aol/micro/server/logback/LogbackPlugin.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.aol.micro.server.logback; - - -import com.aol.micro.server.Plugin; -import com.aol.micro.server.logback.rest.LogbackLoggerResource; -import com.aol.micro.server.logback.rest.LogbackRootLoggerResource; -import com.aol.micro.server.logback.service.LogbackRootLoggerChecker; -import cyclops.collections.immutable.PersistentSetX; -import cyclops.collections.mutable.SetX; - -import java.util.Set; - -/** - * - * @author Ke Wang - * - */ -public class LogbackPlugin implements Plugin { - @Override - public Set springClasses() { - return SetX.of(LogbackRootLoggerResource.class, LogbackRootLoggerChecker.class, LogbackLoggerResource.class); - } - -} diff --git a/micro-logback/src/main/java/com/oath/micro/server/logback/LogbackPlugin.java b/micro-logback/src/main/java/com/oath/micro/server/logback/LogbackPlugin.java new file mode 100644 index 000000000..e666527d5 --- /dev/null +++ b/micro-logback/src/main/java/com/oath/micro/server/logback/LogbackPlugin.java @@ -0,0 +1,23 @@ +package com.oath.micro.server.logback; + + +import com.oath.micro.server.Plugin; +import com.oath.micro.server.logback.rest.LogbackLoggerResource; +import com.oath.micro.server.logback.rest.LogbackRootLoggerResource; +import com.oath.micro.server.logback.service.LogbackRootLoggerChecker; +import cyclops.collections.mutable.SetX; + +import java.util.Set; + +/** + * + * @author Ke Wang + * + */ +public class LogbackPlugin implements Plugin { + @Override + public Set springClasses() { + return SetX.of(LogbackRootLoggerResource.class, LogbackRootLoggerChecker.class, LogbackLoggerResource.class); + } + +} diff --git a/micro-logback/src/main/java/com/aol/micro/server/logback/rest/LogbackLoggerResource.java b/micro-logback/src/main/java/com/oath/micro/server/logback/rest/LogbackLoggerResource.java similarity index 96% rename from micro-logback/src/main/java/com/aol/micro/server/logback/rest/LogbackLoggerResource.java rename to micro-logback/src/main/java/com/oath/micro/server/logback/rest/LogbackLoggerResource.java index bf3a1024f..30faf998a 100644 --- a/micro-logback/src/main/java/com/aol/micro/server/logback/rest/LogbackLoggerResource.java +++ b/micro-logback/src/main/java/com/oath/micro/server/logback/rest/LogbackLoggerResource.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.logback.rest; +package com.oath.micro.server.logback.rest; import javax.ws.rs.GET; import javax.ws.rs.Path; @@ -12,7 +12,7 @@ import ch.qos.logback.classic.Level; import ch.qos.logback.classic.Logger; -import com.aol.micro.server.auto.discovery.SingletonRestResource; +import com.oath.micro.server.auto.discovery.SingletonRestResource; @Component @Path("/logback/logger") diff --git a/micro-logback/src/main/java/com/aol/micro/server/logback/rest/LogbackRootLoggerResource.java b/micro-logback/src/main/java/com/oath/micro/server/logback/rest/LogbackRootLoggerResource.java similarity index 93% rename from micro-logback/src/main/java/com/aol/micro/server/logback/rest/LogbackRootLoggerResource.java rename to micro-logback/src/main/java/com/oath/micro/server/logback/rest/LogbackRootLoggerResource.java index 70208c22c..aa3061436 100644 --- a/micro-logback/src/main/java/com/aol/micro/server/logback/rest/LogbackRootLoggerResource.java +++ b/micro-logback/src/main/java/com/oath/micro/server/logback/rest/LogbackRootLoggerResource.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.logback.rest; +package com.oath.micro.server.logback.rest; import javax.ws.rs.GET; import javax.ws.rs.Path; @@ -13,8 +13,8 @@ import ch.qos.logback.classic.Level; import ch.qos.logback.classic.Logger; -import com.aol.micro.server.auto.discovery.SingletonRestResource; -import com.aol.micro.server.logback.service.LogbackRootLoggerChecker; +import com.oath.micro.server.auto.discovery.SingletonRestResource; +import com.oath.micro.server.logback.service.LogbackRootLoggerChecker; @Component @Path("/logback/rootlogger") diff --git a/micro-logback/src/main/java/com/aol/micro/server/logback/service/LogbackRootLoggerChecker.java b/micro-logback/src/main/java/com/oath/micro/server/logback/service/LogbackRootLoggerChecker.java similarity index 96% rename from micro-logback/src/main/java/com/aol/micro/server/logback/service/LogbackRootLoggerChecker.java rename to micro-logback/src/main/java/com/oath/micro/server/logback/service/LogbackRootLoggerChecker.java index 55d4c7e8e..e0fa676a2 100644 --- a/micro-logback/src/main/java/com/aol/micro/server/logback/service/LogbackRootLoggerChecker.java +++ b/micro-logback/src/main/java/com/oath/micro/server/logback/service/LogbackRootLoggerChecker.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.logback.service; +package com.oath.micro.server.logback.service; import lombok.Getter; import lombok.Setter; diff --git a/micro-logback/src/main/resources/META-INF/services/com.aol.micro.server.Plugin b/micro-logback/src/main/resources/META-INF/services/com.aol.micro.server.Plugin deleted file mode 100644 index 052705e35..000000000 --- a/micro-logback/src/main/resources/META-INF/services/com.aol.micro.server.Plugin +++ /dev/null @@ -1 +0,0 @@ -com.aol.micro.server.logback.LogbackPlugin diff --git a/micro-logback/src/main/resources/META-INF/services/com.oath.micro.server.Plugin b/micro-logback/src/main/resources/META-INF/services/com.oath.micro.server.Plugin new file mode 100644 index 000000000..8ed39f127 --- /dev/null +++ b/micro-logback/src/main/resources/META-INF/services/com.oath.micro.server.Plugin @@ -0,0 +1 @@ +com.oath.micro.server.logback.LogbackPlugin diff --git a/micro-logback/src/test/java/app/level/checker/LogbackRootLoggerChekerRunnerTest.java b/micro-logback/src/test/java/app/level/checker/LogbackRootLoggerChekerRunnerTest.java index addec8120..9ab7f5f58 100644 --- a/micro-logback/src/test/java/app/level/checker/LogbackRootLoggerChekerRunnerTest.java +++ b/micro-logback/src/test/java/app/level/checker/LogbackRootLoggerChekerRunnerTest.java @@ -7,9 +7,9 @@ import org.junit.Before; import org.junit.Test; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.testing.RestAgent; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.testing.RestAgent; @Microserver(properties = { "logback.root.logger.checker.fixed.rate", "1500" }) public class LogbackRootLoggerChekerRunnerTest { diff --git a/micro-logback/src/test/java/app/level/setter/LogbackRootLoggerRunnerTest.java b/micro-logback/src/test/java/app/level/setter/LogbackRootLoggerRunnerTest.java index 3f1aa00d8..f0db26895 100644 --- a/micro-logback/src/test/java/app/level/setter/LogbackRootLoggerRunnerTest.java +++ b/micro-logback/src/test/java/app/level/setter/LogbackRootLoggerRunnerTest.java @@ -7,9 +7,9 @@ import org.junit.Before; import org.junit.Test; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.testing.RestAgent; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.testing.RestAgent; @Microserver(properties = { "log4j.root.logger.checker.active", "false" }) public class LogbackRootLoggerRunnerTest { diff --git a/micro-logback/src/test/java/com/aol/micro/server/testing/RestAgent.java b/micro-logback/src/test/java/com/aol/micro/server/testing/RestAgent.java deleted file mode 100644 index 0f68164b7..000000000 --- a/micro-logback/src/test/java/com/aol/micro/server/testing/RestAgent.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.aol.micro.server.testing; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.Invocation.Builder; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; - -import com.aol.micro.server.rest.jackson.JacksonUtil; - -public class RestAgent { - - - public String getJson(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.get(String.class); - - } - - public String get(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.TEXT_PLAIN); - - return request.get(String.class); - - } - - public T post(String url, Object payload,Class type) { - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); - } - - -} diff --git a/micro-logback/src/test/java/com/aol/micro/server/log4j/service/LogbackRootLoggerCheckerTest.java b/micro-logback/src/test/java/com/oath/micro/server/log4j/service/LogbackRootLoggerCheckerTest.java similarity index 89% rename from micro-logback/src/test/java/com/aol/micro/server/log4j/service/LogbackRootLoggerCheckerTest.java rename to micro-logback/src/test/java/com/oath/micro/server/log4j/service/LogbackRootLoggerCheckerTest.java index 23b09391d..6a9936508 100644 --- a/micro-logback/src/test/java/com/aol/micro/server/log4j/service/LogbackRootLoggerCheckerTest.java +++ b/micro-logback/src/test/java/com/oath/micro/server/log4j/service/LogbackRootLoggerCheckerTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.log4j.service; +package com.oath.micro.server.log4j.service; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; @@ -10,7 +10,7 @@ import ch.qos.logback.classic.Level; import ch.qos.logback.classic.Logger; -import com.aol.micro.server.logback.service.LogbackRootLoggerChecker; +import com.oath.micro.server.logback.service.LogbackRootLoggerChecker; diff --git a/micro-logback/src/test/java/com/aol/micro/server/logback/rest/LogbackLoggerResourceTest.java b/micro-logback/src/test/java/com/oath/micro/server/logback/rest/LogbackLoggerResourceTest.java similarity index 96% rename from micro-logback/src/test/java/com/aol/micro/server/logback/rest/LogbackLoggerResourceTest.java rename to micro-logback/src/test/java/com/oath/micro/server/logback/rest/LogbackLoggerResourceTest.java index 824903059..f8e9e693c 100644 --- a/micro-logback/src/test/java/com/aol/micro/server/logback/rest/LogbackLoggerResourceTest.java +++ b/micro-logback/src/test/java/com/oath/micro/server/logback/rest/LogbackLoggerResourceTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.logback.rest; +package com.oath.micro.server.logback.rest; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; diff --git a/micro-logback/src/test/java/com/aol/micro/server/logback/rest/LogbackLoggerRunnerTest.java b/micro-logback/src/test/java/com/oath/micro/server/logback/rest/LogbackLoggerRunnerTest.java similarity index 76% rename from micro-logback/src/test/java/com/aol/micro/server/logback/rest/LogbackLoggerRunnerTest.java rename to micro-logback/src/test/java/com/oath/micro/server/logback/rest/LogbackLoggerRunnerTest.java index bbd59ff9b..dd4192948 100644 --- a/micro-logback/src/test/java/com/aol/micro/server/logback/rest/LogbackLoggerRunnerTest.java +++ b/micro-logback/src/test/java/com/oath/micro/server/logback/rest/LogbackLoggerRunnerTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.logback.rest; +package com.oath.micro.server.logback.rest; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; @@ -7,9 +7,9 @@ import org.junit.Before; import org.junit.Test; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.testing.RestAgent; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.testing.RestAgent; @Microserver public class LogbackLoggerRunnerTest { diff --git a/micro-logback/src/test/java/com/aol/micro/server/logback/rest/LogbackRootLoggerResourceTest.java b/micro-logback/src/test/java/com/oath/micro/server/logback/rest/LogbackRootLoggerResourceTest.java similarity index 95% rename from micro-logback/src/test/java/com/aol/micro/server/logback/rest/LogbackRootLoggerResourceTest.java rename to micro-logback/src/test/java/com/oath/micro/server/logback/rest/LogbackRootLoggerResourceTest.java index f630d553c..266aaaa75 100644 --- a/micro-logback/src/test/java/com/aol/micro/server/logback/rest/LogbackRootLoggerResourceTest.java +++ b/micro-logback/src/test/java/com/oath/micro/server/logback/rest/LogbackRootLoggerResourceTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.logback.rest; +package com.oath.micro.server.logback.rest; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; diff --git a/micro-logback/src/test/java/com/aol/micro/server/logback/rest/LogbackRootLoggerRunnerTest.java b/micro-logback/src/test/java/com/oath/micro/server/logback/rest/LogbackRootLoggerRunnerTest.java similarity index 76% rename from micro-logback/src/test/java/com/aol/micro/server/logback/rest/LogbackRootLoggerRunnerTest.java rename to micro-logback/src/test/java/com/oath/micro/server/logback/rest/LogbackRootLoggerRunnerTest.java index 7a5b30656..71eb449ec 100644 --- a/micro-logback/src/test/java/com/aol/micro/server/logback/rest/LogbackRootLoggerRunnerTest.java +++ b/micro-logback/src/test/java/com/oath/micro/server/logback/rest/LogbackRootLoggerRunnerTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.logback.rest; +package com.oath.micro.server.logback.rest; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; @@ -7,9 +7,9 @@ import org.junit.Before; import org.junit.Test; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.testing.RestAgent; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.testing.RestAgent; @Microserver public class LogbackRootLoggerRunnerTest { diff --git a/micro-logback/src/test/java/com/oath/micro/server/testing/RestAgent.java b/micro-logback/src/test/java/com/oath/micro/server/testing/RestAgent.java new file mode 100644 index 000000000..b2b86303e --- /dev/null +++ b/micro-logback/src/test/java/com/oath/micro/server/testing/RestAgent.java @@ -0,0 +1,53 @@ +package com.oath.micro.server.testing; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.Invocation.Builder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; + +import com.oath.micro.server.rest.jackson.JacksonUtil; + +public class RestAgent { + + + public String getJson(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.get(String.class); + + } + + public String get(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.TEXT_PLAIN); + + return request.get(String.class); + + } + + public T post(String url, Object payload,Class type) { + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); + } + + +} diff --git a/micro-machine-stats/src/main/java/com/aol/micro/server/machine/stats/sigar/plugin/MachineStatsPlugin.java b/micro-machine-stats/src/main/java/com/aol/micro/server/machine/stats/sigar/plugin/MachineStatsPlugin.java deleted file mode 100644 index 0d5f32b10..000000000 --- a/micro-machine-stats/src/main/java/com/aol/micro/server/machine/stats/sigar/plugin/MachineStatsPlugin.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.aol.micro.server.machine.stats.sigar.plugin; - - -import com.aol.micro.server.Plugin; -import com.aol.micro.server.machine.stats.sigar.MachineStatsChecker; -import com.aol.micro.server.machine.stats.sigar.SigarStats; -import com.aol.micro.server.machine.stats.sigar.StatsServletContextListener; -import com.aol.micro.server.machine.stats.sigar.rest.StatsResource; -import cyclops.collections.immutable.PersistentSetX; -import cyclops.collections.mutable.SetX; - -import java.util.Set; - -/** - * - * Collections of Spring configuration classes (Classes annotated with @Configuration) - * that configure various useful pieces of functionality - such as property file loading, - * datasources, scheduling etc - * - * @author johnmcclean - * - */ -public class MachineStatsPlugin implements Plugin { - - @Override - public Set springClasses() { - return SetX.of(StatsResource.class, MachineStatsChecker.class, StatsServletContextListener.class, - SigarStats.class); - } - -} diff --git a/micro-machine-stats/src/main/java/com/aol/micro/server/machine/stats/sigar/rest/StatsResource.java b/micro-machine-stats/src/main/java/com/aol/micro/server/machine/stats/sigar/rest/StatsResource.java deleted file mode 100644 index ac191a293..000000000 --- a/micro-machine-stats/src/main/java/com/aol/micro/server/machine/stats/sigar/rest/StatsResource.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.aol.micro.server.machine.stats.sigar.rest; - - - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.hyperic.sigar.Sigar; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.SingletonRestResource; -import com.aol.micro.server.machine.stats.sigar.MachineStats; -import com.aol.micro.server.machine.stats.sigar.MachineStatsChecker; - -@Path("/stats") -public class StatsResource implements SingletonRestResource { - - - private final MachineStatsChecker machineStatsChecker; - - @Autowired - public StatsResource(MachineStatsChecker machineStatsChecker){ - this.machineStatsChecker = machineStatsChecker; - } - - @GET - @Path("/machine") - @Produces("application/json") - public MachineStats getMachineStats() { - return machineStatsChecker.getStats(new Sigar()); - } -} diff --git a/micro-machine-stats/src/main/java/com/aol/micro/server/machine/stats/sigar/CpuStats.java b/micro-machine-stats/src/main/java/com/oath/micro/server/machine/stats/sigar/CpuStats.java similarity index 97% rename from micro-machine-stats/src/main/java/com/aol/micro/server/machine/stats/sigar/CpuStats.java rename to micro-machine-stats/src/main/java/com/oath/micro/server/machine/stats/sigar/CpuStats.java index df41d96cc..1ed5ffe85 100644 --- a/micro-machine-stats/src/main/java/com/aol/micro/server/machine/stats/sigar/CpuStats.java +++ b/micro-machine-stats/src/main/java/com/oath/micro/server/machine/stats/sigar/CpuStats.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.machine.stats.sigar; +package com.oath.micro.server.machine.stats.sigar; import java.io.Serializable; import java.util.Map; diff --git a/micro-machine-stats/src/main/java/com/aol/micro/server/machine/stats/sigar/MachineStats.java b/micro-machine-stats/src/main/java/com/oath/micro/server/machine/stats/sigar/MachineStats.java similarity index 96% rename from micro-machine-stats/src/main/java/com/aol/micro/server/machine/stats/sigar/MachineStats.java rename to micro-machine-stats/src/main/java/com/oath/micro/server/machine/stats/sigar/MachineStats.java index c6dc05427..f274cd2ec 100644 --- a/micro-machine-stats/src/main/java/com/aol/micro/server/machine/stats/sigar/MachineStats.java +++ b/micro-machine-stats/src/main/java/com/oath/micro/server/machine/stats/sigar/MachineStats.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.machine.stats.sigar; +package com.oath.micro.server.machine.stats.sigar; import java.io.Serializable; import java.util.Map; diff --git a/micro-machine-stats/src/main/java/com/aol/micro/server/machine/stats/sigar/MachineStatsChecker.java b/micro-machine-stats/src/main/java/com/oath/micro/server/machine/stats/sigar/MachineStatsChecker.java similarity index 98% rename from micro-machine-stats/src/main/java/com/aol/micro/server/machine/stats/sigar/MachineStatsChecker.java rename to micro-machine-stats/src/main/java/com/oath/micro/server/machine/stats/sigar/MachineStatsChecker.java index a00506042..3eb4697a9 100644 --- a/micro-machine-stats/src/main/java/com/aol/micro/server/machine/stats/sigar/MachineStatsChecker.java +++ b/micro-machine-stats/src/main/java/com/oath/micro/server/machine/stats/sigar/MachineStatsChecker.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.machine.stats.sigar; +package com.oath.micro.server.machine.stats.sigar; import org.hyperic.sigar.Sigar; import org.hyperic.sigar.SigarException; diff --git a/micro-machine-stats/src/main/java/com/aol/micro/server/machine/stats/sigar/MemoryStats.java b/micro-machine-stats/src/main/java/com/oath/micro/server/machine/stats/sigar/MemoryStats.java similarity index 97% rename from micro-machine-stats/src/main/java/com/aol/micro/server/machine/stats/sigar/MemoryStats.java rename to micro-machine-stats/src/main/java/com/oath/micro/server/machine/stats/sigar/MemoryStats.java index 6eaf1ef2c..6ec614cc3 100644 --- a/micro-machine-stats/src/main/java/com/aol/micro/server/machine/stats/sigar/MemoryStats.java +++ b/micro-machine-stats/src/main/java/com/oath/micro/server/machine/stats/sigar/MemoryStats.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.machine.stats.sigar; +package com.oath.micro.server.machine.stats.sigar; import java.io.Serializable; import java.util.Map; diff --git a/micro-machine-stats/src/main/java/com/aol/micro/server/machine/stats/sigar/SigarStats.java b/micro-machine-stats/src/main/java/com/oath/micro/server/machine/stats/sigar/SigarStats.java similarity index 91% rename from micro-machine-stats/src/main/java/com/aol/micro/server/machine/stats/sigar/SigarStats.java rename to micro-machine-stats/src/main/java/com/oath/micro/server/machine/stats/sigar/SigarStats.java index a5f1fc7c0..039afec81 100644 --- a/micro-machine-stats/src/main/java/com/aol/micro/server/machine/stats/sigar/SigarStats.java +++ b/micro-machine-stats/src/main/java/com/oath/micro/server/machine/stats/sigar/SigarStats.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.machine.stats.sigar; +package com.oath.micro.server.machine.stats.sigar; import java.util.Map; @@ -7,7 +7,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; -import com.aol.micro.server.StatsSupplier; +import com.oath.micro.server.StatsSupplier; @Component public class SigarStats implements StatsSupplier { diff --git a/micro-machine-stats/src/main/java/com/aol/micro/server/machine/stats/sigar/StatsServletContextListener.java b/micro-machine-stats/src/main/java/com/oath/micro/server/machine/stats/sigar/StatsServletContextListener.java similarity index 96% rename from micro-machine-stats/src/main/java/com/aol/micro/server/machine/stats/sigar/StatsServletContextListener.java rename to micro-machine-stats/src/main/java/com/oath/micro/server/machine/stats/sigar/StatsServletContextListener.java index b29c2b395..5543b0846 100644 --- a/micro-machine-stats/src/main/java/com/aol/micro/server/machine/stats/sigar/StatsServletContextListener.java +++ b/micro-machine-stats/src/main/java/com/oath/micro/server/machine/stats/sigar/StatsServletContextListener.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.machine.stats.sigar; +package com.oath.micro.server.machine.stats.sigar; import java.io.File; diff --git a/micro-machine-stats/src/main/java/com/aol/micro/server/machine/stats/sigar/SwapStats.java b/micro-machine-stats/src/main/java/com/oath/micro/server/machine/stats/sigar/SwapStats.java similarity index 96% rename from micro-machine-stats/src/main/java/com/aol/micro/server/machine/stats/sigar/SwapStats.java rename to micro-machine-stats/src/main/java/com/oath/micro/server/machine/stats/sigar/SwapStats.java index 7ac332be5..7ed24a415 100644 --- a/micro-machine-stats/src/main/java/com/aol/micro/server/machine/stats/sigar/SwapStats.java +++ b/micro-machine-stats/src/main/java/com/oath/micro/server/machine/stats/sigar/SwapStats.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.machine.stats.sigar; +package com.oath.micro.server.machine.stats.sigar; import java.io.Serializable; import java.util.Map; diff --git a/micro-machine-stats/src/main/java/com/oath/micro/server/machine/stats/sigar/plugin/MachineStatsPlugin.java b/micro-machine-stats/src/main/java/com/oath/micro/server/machine/stats/sigar/plugin/MachineStatsPlugin.java new file mode 100644 index 000000000..3a11f3d0b --- /dev/null +++ b/micro-machine-stats/src/main/java/com/oath/micro/server/machine/stats/sigar/plugin/MachineStatsPlugin.java @@ -0,0 +1,30 @@ +package com.oath.micro.server.machine.stats.sigar.plugin; + + +import com.oath.micro.server.Plugin; +import com.oath.micro.server.machine.stats.sigar.MachineStatsChecker; +import com.oath.micro.server.machine.stats.sigar.SigarStats; +import com.oath.micro.server.machine.stats.sigar.StatsServletContextListener; +import com.oath.micro.server.machine.stats.sigar.rest.StatsResource; +import cyclops.collections.mutable.SetX; + +import java.util.Set; + +/** + * + * Collections of Spring configuration classes (Classes annotated with @Configuration) + * that configure various useful pieces of functionality - such as property file loading, + * datasources, scheduling etc + * + * @author johnmcclean + * + */ +public class MachineStatsPlugin implements Plugin { + + @Override + public Set springClasses() { + return SetX.of(StatsResource.class, MachineStatsChecker.class, StatsServletContextListener.class, + SigarStats.class); + } + +} diff --git a/micro-machine-stats/src/main/java/com/oath/micro/server/machine/stats/sigar/rest/StatsResource.java b/micro-machine-stats/src/main/java/com/oath/micro/server/machine/stats/sigar/rest/StatsResource.java new file mode 100644 index 000000000..510e54517 --- /dev/null +++ b/micro-machine-stats/src/main/java/com/oath/micro/server/machine/stats/sigar/rest/StatsResource.java @@ -0,0 +1,33 @@ +package com.oath.micro.server.machine.stats.sigar.rest; + + + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.hyperic.sigar.Sigar; +import org.springframework.beans.factory.annotation.Autowired; + +import com.oath.micro.server.auto.discovery.SingletonRestResource; +import com.oath.micro.server.machine.stats.sigar.MachineStats; +import com.oath.micro.server.machine.stats.sigar.MachineStatsChecker; + +@Path("/stats") +public class StatsResource implements SingletonRestResource { + + + private final MachineStatsChecker machineStatsChecker; + + @Autowired + public StatsResource(MachineStatsChecker machineStatsChecker){ + this.machineStatsChecker = machineStatsChecker; + } + + @GET + @Path("/machine") + @Produces("application/json") + public MachineStats getMachineStats() { + return machineStatsChecker.getStats(new Sigar()); + } +} diff --git a/micro-machine-stats/src/main/resources/META-INF/services/com.aol.micro.server.Plugin b/micro-machine-stats/src/main/resources/META-INF/services/com.aol.micro.server.Plugin deleted file mode 100644 index a120f70f7..000000000 --- a/micro-machine-stats/src/main/resources/META-INF/services/com.aol.micro.server.Plugin +++ /dev/null @@ -1 +0,0 @@ -com.aol.micro.server.machine.stats.sigar.plugin.MachineStatsPlugin \ No newline at end of file diff --git a/micro-machine-stats/src/main/resources/META-INF/services/com.oath.micro.server.Plugin b/micro-machine-stats/src/main/resources/META-INF/services/com.oath.micro.server.Plugin new file mode 100644 index 000000000..fa31f6820 --- /dev/null +++ b/micro-machine-stats/src/main/resources/META-INF/services/com.oath.micro.server.Plugin @@ -0,0 +1 @@ +com.oath.micro.server.machine.stats.sigar.plugin.MachineStatsPlugin \ No newline at end of file diff --git a/micro-machine-stats/src/test/java/app/sigar/com/aol/micro/server/SingleClassApp.java b/micro-machine-stats/src/test/java/app/sigar/com/aol/micro/server/SingleClassApp.java deleted file mode 100644 index 0159898bc..000000000 --- a/micro-machine-stats/src/test/java/app/sigar/com/aol/micro/server/SingleClassApp.java +++ /dev/null @@ -1,24 +0,0 @@ -package app.sigar.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.Rest; - -@Rest -@Path("/status") -public class SingleClassApp { - - public static void main(String[] args){ - new MicroserverApp(()-> "simple-app").run(); - } - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "ok"; - } - -} \ No newline at end of file diff --git a/micro-machine-stats/src/test/java/app/sigar/com/oath/micro/server/SingleClassApp.java b/micro-machine-stats/src/test/java/app/sigar/com/oath/micro/server/SingleClassApp.java new file mode 100644 index 000000000..53b12ff37 --- /dev/null +++ b/micro-machine-stats/src/test/java/app/sigar/com/oath/micro/server/SingleClassApp.java @@ -0,0 +1,24 @@ +package app.sigar.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.auto.discovery.Rest; + +@Rest +@Path("/status") +public class SingleClassApp { + + public static void main(String[] args){ + new MicroserverApp(()-> "simple-app").run(); + } + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "ok"; + } + +} \ No newline at end of file diff --git a/micro-machine-stats/src/test/java/app/sigar/com/aol/micro/server/StatsRunnerTest.java b/micro-machine-stats/src/test/java/app/sigar/com/oath/micro/server/StatsRunnerTest.java similarity index 83% rename from micro-machine-stats/src/test/java/app/sigar/com/aol/micro/server/StatsRunnerTest.java rename to micro-machine-stats/src/test/java/app/sigar/com/oath/micro/server/StatsRunnerTest.java index 060433c1a..0c5ba0edd 100644 --- a/micro-machine-stats/src/test/java/app/sigar/com/aol/micro/server/StatsRunnerTest.java +++ b/micro-machine-stats/src/test/java/app/sigar/com/oath/micro/server/StatsRunnerTest.java @@ -1,4 +1,4 @@ -package app.sigar.com.aol.micro.server; +package app.sigar.com.oath.micro.server; import static org.hamcrest.CoreMatchers.containsString; import static org.junit.Assert.assertThat; @@ -11,10 +11,10 @@ import org.junit.Before; import org.junit.Test; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.testing.RestAgent; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.module.ConfigurableModule; +import com.oath.micro.server.testing.RestAgent; @Microserver(properties = { "machine.stats.deploy.dir", "/tmp" }) public class StatsRunnerTest { diff --git a/micro-machine-stats/src/test/java/com/aol/micro/server/testing/RestAgent.java b/micro-machine-stats/src/test/java/com/aol/micro/server/testing/RestAgent.java deleted file mode 100644 index 991ffed12..000000000 --- a/micro-machine-stats/src/test/java/com/aol/micro/server/testing/RestAgent.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.aol.micro.server.testing; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Invocation.Builder; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -public class RestAgent { - - - public String get(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.get(String.class); - - } - - - - -} diff --git a/micro-machine-stats/src/test/java/com/aol/micro/server/machine/stats/sigar/MachineStatsCheckerTest.java b/micro-machine-stats/src/test/java/com/oath/micro/server/machine/stats/sigar/MachineStatsCheckerTest.java similarity index 95% rename from micro-machine-stats/src/test/java/com/aol/micro/server/machine/stats/sigar/MachineStatsCheckerTest.java rename to micro-machine-stats/src/test/java/com/oath/micro/server/machine/stats/sigar/MachineStatsCheckerTest.java index 1b5e90c63..5744507f5 100644 --- a/micro-machine-stats/src/test/java/com/aol/micro/server/machine/stats/sigar/MachineStatsCheckerTest.java +++ b/micro-machine-stats/src/test/java/com/oath/micro/server/machine/stats/sigar/MachineStatsCheckerTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.machine.stats.sigar; +package com.oath.micro.server.machine.stats.sigar; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; @@ -14,8 +14,6 @@ import org.junit.Before; import org.junit.Test; -import com.aol.micro.server.machine.stats.sigar.MachineStatsChecker; - public class MachineStatsCheckerTest { private Sigar sigar; diff --git a/micro-machine-stats/src/test/java/com/aol/micro/server/machine/stats/sigar/MachineStatsTest.java b/micro-machine-stats/src/test/java/com/oath/micro/server/machine/stats/sigar/MachineStatsTest.java similarity index 92% rename from micro-machine-stats/src/test/java/com/aol/micro/server/machine/stats/sigar/MachineStatsTest.java rename to micro-machine-stats/src/test/java/com/oath/micro/server/machine/stats/sigar/MachineStatsTest.java index 49265614f..3d1422c10 100644 --- a/micro-machine-stats/src/test/java/com/aol/micro/server/machine/stats/sigar/MachineStatsTest.java +++ b/micro-machine-stats/src/test/java/com/oath/micro/server/machine/stats/sigar/MachineStatsTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.machine.stats.sigar; +package com.oath.micro.server.machine.stats.sigar; import org.junit.Test; diff --git a/micro-machine-stats/src/test/java/com/aol/micro/server/machine/stats/sigar/StatsServletContextListenerTest.groovy b/micro-machine-stats/src/test/java/com/oath/micro/server/machine/stats/sigar/StatsServletContextListenerTest.groovy similarity index 90% rename from micro-machine-stats/src/test/java/com/aol/micro/server/machine/stats/sigar/StatsServletContextListenerTest.groovy rename to micro-machine-stats/src/test/java/com/oath/micro/server/machine/stats/sigar/StatsServletContextListenerTest.groovy index e1857784c..ca39650b9 100644 --- a/micro-machine-stats/src/test/java/com/aol/micro/server/machine/stats/sigar/StatsServletContextListenerTest.groovy +++ b/micro-machine-stats/src/test/java/com/oath/micro/server/machine/stats/sigar/StatsServletContextListenerTest.groovy @@ -1,9 +1,8 @@ -package com.aol.micro.server.machine.stats.sigar; +package com.oath.micro.server.machine.stats.sigar; import static org.hamcrest.Matchers.is import static org.junit.Assert.assertThat import static org.mockito.Mockito.mock -import static org.mockito.Mockito.when import javax.servlet.ServletContext import javax.servlet.ServletContextEvent diff --git a/micro-machine-stats/src/test/java/com/aol/micro/server/machine/stats/sigar/rest/StatsResourceTest.java b/micro-machine-stats/src/test/java/com/oath/micro/server/machine/stats/sigar/rest/StatsResourceTest.java similarity index 81% rename from micro-machine-stats/src/test/java/com/aol/micro/server/machine/stats/sigar/rest/StatsResourceTest.java rename to micro-machine-stats/src/test/java/com/oath/micro/server/machine/stats/sigar/rest/StatsResourceTest.java index 27afc618f..95656d072 100644 --- a/micro-machine-stats/src/test/java/com/aol/micro/server/machine/stats/sigar/rest/StatsResourceTest.java +++ b/micro-machine-stats/src/test/java/com/oath/micro/server/machine/stats/sigar/rest/StatsResourceTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.machine.stats.sigar.rest; +package com.oath.micro.server.machine.stats.sigar.rest; import static org.mockito.Matchers.anyObject; @@ -11,8 +11,8 @@ import org.junit.Before; import org.junit.Test; -import com.aol.micro.server.machine.stats.sigar.MachineStats; -import com.aol.micro.server.machine.stats.sigar.MachineStatsChecker; +import com.oath.micro.server.machine.stats.sigar.MachineStats; +import com.oath.micro.server.machine.stats.sigar.MachineStatsChecker; public class StatsResourceTest { diff --git a/micro-machine-stats/src/test/java/com/oath/micro/server/testing/RestAgent.java b/micro-machine-stats/src/test/java/com/oath/micro/server/testing/RestAgent.java new file mode 100644 index 000000000..a5f4fe51a --- /dev/null +++ b/micro-machine-stats/src/test/java/com/oath/micro/server/testing/RestAgent.java @@ -0,0 +1,28 @@ +package com.oath.micro.server.testing; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Invocation.Builder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; + +public class RestAgent { + + + public String get(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.get(String.class); + + } + + + + +} diff --git a/micro-manifest-comparator/src/main/java/com/aol/micro/server/distributed/DistributedMap.java b/micro-manifest-comparator/src/main/java/com/oath/micro/server/distributed/DistributedMap.java similarity index 79% rename from micro-manifest-comparator/src/main/java/com/aol/micro/server/distributed/DistributedMap.java rename to micro-manifest-comparator/src/main/java/com/oath/micro/server/distributed/DistributedMap.java index 9dd77084b..dba6b35ca 100644 --- a/micro-manifest-comparator/src/main/java/com/aol/micro/server/distributed/DistributedMap.java +++ b/micro-manifest-comparator/src/main/java/com/oath/micro/server/distributed/DistributedMap.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.distributed; +package com.oath.micro.server.distributed; import java.util.Optional; diff --git a/micro-manifest-comparator/src/main/java/com/aol/micro/server/manifest/Data.java b/micro-manifest-comparator/src/main/java/com/oath/micro/server/manifest/Data.java similarity index 91% rename from micro-manifest-comparator/src/main/java/com/aol/micro/server/manifest/Data.java rename to micro-manifest-comparator/src/main/java/com/oath/micro/server/manifest/Data.java index d5936c8a5..f7bcabf45 100644 --- a/micro-manifest-comparator/src/main/java/com/aol/micro/server/manifest/Data.java +++ b/micro-manifest-comparator/src/main/java/com/oath/micro/server/manifest/Data.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.manifest; +package com.oath.micro.server.manifest; import java.io.Serializable; import java.util.Date; diff --git a/micro-manifest-comparator/src/main/java/com/aol/micro/server/manifest/ManifestComparator.java b/micro-manifest-comparator/src/main/java/com/oath/micro/server/manifest/ManifestComparator.java similarity index 93% rename from micro-manifest-comparator/src/main/java/com/aol/micro/server/manifest/ManifestComparator.java rename to micro-manifest-comparator/src/main/java/com/oath/micro/server/manifest/ManifestComparator.java index dfda579dc..13f70e884 100644 --- a/micro-manifest-comparator/src/main/java/com/aol/micro/server/manifest/ManifestComparator.java +++ b/micro-manifest-comparator/src/main/java/com/oath/micro/server/manifest/ManifestComparator.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.manifest; +package com.oath.micro.server.manifest; public interface ManifestComparator { public ManifestComparator withKey(String key); diff --git a/micro-manifest-comparator/src/main/java/com/aol/micro/server/manifest/ManifestComparatorKeyNotFoundException.java b/micro-manifest-comparator/src/main/java/com/oath/micro/server/manifest/ManifestComparatorKeyNotFoundException.java similarity index 85% rename from micro-manifest-comparator/src/main/java/com/aol/micro/server/manifest/ManifestComparatorKeyNotFoundException.java rename to micro-manifest-comparator/src/main/java/com/oath/micro/server/manifest/ManifestComparatorKeyNotFoundException.java index b9410814d..a3f7aa937 100644 --- a/micro-manifest-comparator/src/main/java/com/aol/micro/server/manifest/ManifestComparatorKeyNotFoundException.java +++ b/micro-manifest-comparator/src/main/java/com/oath/micro/server/manifest/ManifestComparatorKeyNotFoundException.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.manifest; +package com.oath.micro.server.manifest; public class ManifestComparatorKeyNotFoundException extends RuntimeException { diff --git a/micro-manifest-comparator/src/main/java/com/aol/micro/server/manifest/VersionedKey.java b/micro-manifest-comparator/src/main/java/com/oath/micro/server/manifest/VersionedKey.java similarity index 87% rename from micro-manifest-comparator/src/main/java/com/aol/micro/server/manifest/VersionedKey.java rename to micro-manifest-comparator/src/main/java/com/oath/micro/server/manifest/VersionedKey.java index 0340bb95a..2f9eb0a26 100644 --- a/micro-manifest-comparator/src/main/java/com/aol/micro/server/manifest/VersionedKey.java +++ b/micro-manifest-comparator/src/main/java/com/oath/micro/server/manifest/VersionedKey.java @@ -1,11 +1,11 @@ -package com.aol.micro.server.manifest; +package com.oath.micro.server.manifest; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; -import com.aol.micro.server.rest.jackson.JacksonUtil; +import com.oath.micro.server.rest.jackson.JacksonUtil; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/micro-manifest-comparator/src/test/java/com/aol/micro/server/manifest/ManifestComparatorKeyNotFoundExceptionTest.java b/micro-manifest-comparator/src/test/java/com/aol/micro/server/manifest/ManifestComparatorKeyNotFoundExceptionTest.java index 3d6a5084a..4d8fc06b2 100644 --- a/micro-manifest-comparator/src/test/java/com/aol/micro/server/manifest/ManifestComparatorKeyNotFoundExceptionTest.java +++ b/micro-manifest-comparator/src/test/java/com/aol/micro/server/manifest/ManifestComparatorKeyNotFoundExceptionTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.manifest; +package com.oath.micro.server.manifest; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; diff --git a/micro-metrics-datadog/src/main/java/com/aol/micro/server/datadog/metrics/DatadogMetricsConfigurer.java b/micro-metrics-datadog/src/main/java/com/oath/micro/server/datadog/metrics/DatadogMetricsConfigurer.java similarity index 98% rename from micro-metrics-datadog/src/main/java/com/aol/micro/server/datadog/metrics/DatadogMetricsConfigurer.java rename to micro-metrics-datadog/src/main/java/com/oath/micro/server/datadog/metrics/DatadogMetricsConfigurer.java index 984aef913..7fc590e4a 100644 --- a/micro-metrics-datadog/src/main/java/com/aol/micro/server/datadog/metrics/DatadogMetricsConfigurer.java +++ b/micro-metrics-datadog/src/main/java/com/oath/micro/server/datadog/metrics/DatadogMetricsConfigurer.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.datadog.metrics; +package com.oath.micro.server.datadog.metrics; import java.util.Arrays; import java.util.EnumSet; diff --git a/micro-metrics-datadog/src/main/java/com/aol/micro/server/datadog/metrics/DatadogMetricsPlugin.java b/micro-metrics-datadog/src/main/java/com/oath/micro/server/datadog/metrics/DatadogMetricsPlugin.java similarity index 78% rename from micro-metrics-datadog/src/main/java/com/aol/micro/server/datadog/metrics/DatadogMetricsPlugin.java rename to micro-metrics-datadog/src/main/java/com/oath/micro/server/datadog/metrics/DatadogMetricsPlugin.java index 0def93101..821ec197a 100644 --- a/micro-metrics-datadog/src/main/java/com/aol/micro/server/datadog/metrics/DatadogMetricsPlugin.java +++ b/micro-metrics-datadog/src/main/java/com/oath/micro/server/datadog/metrics/DatadogMetricsPlugin.java @@ -1,7 +1,6 @@ -package com.aol.micro.server.datadog.metrics; +package com.oath.micro.server.datadog.metrics; -import com.aol.micro.server.Plugin; -import cyclops.collections.immutable.PersistentSetX; +import com.oath.micro.server.Plugin; import cyclops.collections.mutable.SetX; import java.util.Set; diff --git a/micro-metrics-datadog/src/main/resources/META-INF/services/com.aol.micro.server.Plugin b/micro-metrics-datadog/src/main/resources/META-INF/services/com.aol.micro.server.Plugin deleted file mode 100644 index 19054bede..000000000 --- a/micro-metrics-datadog/src/main/resources/META-INF/services/com.aol.micro.server.Plugin +++ /dev/null @@ -1 +0,0 @@ -com.aol.micro.server.datadog.metrics.DatadogMetricsPlugin \ No newline at end of file diff --git a/micro-metrics-datadog/src/main/resources/META-INF/services/com.oath.micro.server.Plugin b/micro-metrics-datadog/src/main/resources/META-INF/services/com.oath.micro.server.Plugin new file mode 100644 index 000000000..8ab22e22d --- /dev/null +++ b/micro-metrics-datadog/src/main/resources/META-INF/services/com.oath.micro.server.Plugin @@ -0,0 +1 @@ +com.oath.micro.server.datadog.metrics.DatadogMetricsPlugin \ No newline at end of file diff --git a/micro-metrics-datadog/src/test/java/app/datadog/metrics/com/aol/micro/server/DatadogMetricsRunnerTest.java b/micro-metrics-datadog/src/test/java/app/datadog/metrics/com/aol/micro/server/DatadogMetricsRunnerTest.java index 377563b1e..796cdda74 100644 --- a/micro-metrics-datadog/src/test/java/app/datadog/metrics/com/aol/micro/server/DatadogMetricsRunnerTest.java +++ b/micro-metrics-datadog/src/test/java/app/datadog/metrics/com/aol/micro/server/DatadogMetricsRunnerTest.java @@ -1,6 +1,6 @@ package app.datadog.metrics.com.aol.micro.server; -import com.aol.micro.server.testing.RestAgent; +import com.oath.micro.server.testing.RestAgent; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/micro-metrics-datadog/src/test/java/app/datadog/metrics/com/aol/micro/server/DatadogMetricsStatusResource.java b/micro-metrics-datadog/src/test/java/app/datadog/metrics/com/aol/micro/server/DatadogMetricsStatusResource.java index 4c930082f..529b61179 100644 --- a/micro-metrics-datadog/src/test/java/app/datadog/metrics/com/aol/micro/server/DatadogMetricsStatusResource.java +++ b/micro-metrics-datadog/src/test/java/app/datadog/metrics/com/aol/micro/server/DatadogMetricsStatusResource.java @@ -1,7 +1,7 @@ package app.datadog.metrics.com.aol.micro.server; -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.auto.discovery.RestResource; +import com.oath.micro.server.auto.discovery.Rest; +import com.oath.micro.server.auto.discovery.RestResource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; diff --git a/micro-metrics-datadog/src/test/java/app/datadog/metrics/com/aol/micro/server/DatadogTestMain.java b/micro-metrics-datadog/src/test/java/app/datadog/metrics/com/aol/micro/server/DatadogTestMain.java index ac7951cb2..8620b840e 100644 --- a/micro-metrics-datadog/src/test/java/app/datadog/metrics/com/aol/micro/server/DatadogTestMain.java +++ b/micro-metrics-datadog/src/test/java/app/datadog/metrics/com/aol/micro/server/DatadogTestMain.java @@ -1,9 +1,9 @@ package app.datadog.metrics.com.aol.micro.server; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; -@Microserver(basePackages = { "app.datadog.metrics.com.aol.micro.server", "com.aol.micro.server.datadog.metrics", "com.aol.micro.server.event.metrics"}) +@Microserver(basePackages = { "app.datadog.metrics.com.oath.micro.server", "com.oath.micro.server.datadog.metrics", "com.oath.micro.server.event.metrics"}) public class DatadogTestMain { public static final String CONTEXT = "datadog-app"; diff --git a/micro-metrics-datadog/src/test/java/app/datadog/metrics/com/aol/micro/server/DatadogTestService.java b/micro-metrics-datadog/src/test/java/app/datadog/metrics/com/aol/micro/server/DatadogTestService.java index dc50e4c09..3b88de7c1 100644 --- a/micro-metrics-datadog/src/test/java/app/datadog/metrics/com/aol/micro/server/DatadogTestService.java +++ b/micro-metrics-datadog/src/test/java/app/datadog/metrics/com/aol/micro/server/DatadogTestService.java @@ -1,7 +1,7 @@ package app.datadog.metrics.com.aol.micro.server; -import com.aol.micro.server.errors.ErrorCode; -import com.aol.micro.server.errors.InvalidStateException; +import com.oath.micro.server.errors.ErrorCode; +import com.oath.micro.server.errors.InvalidStateException; import org.springframework.stereotype.Component; @Component diff --git a/micro-metrics-datadog/src/test/java/com/aol/micro/server/testing/RestAgent.java b/micro-metrics-datadog/src/test/java/com/aol/micro/server/testing/RestAgent.java deleted file mode 100644 index 519a4fc0c..000000000 --- a/micro-metrics-datadog/src/test/java/com/aol/micro/server/testing/RestAgent.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.aol.micro.server.testing; - -import com.aol.micro.server.rest.jackson.JacksonUtil; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.Invocation.Builder; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; - -public class RestAgent { - - - public String getJson(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.get(String.class); - - } - - public String get(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.TEXT_PLAIN); - - return request.get(String.class); - - } - - public T post(String url, Object payload,Class type) { - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); - } - - -} diff --git a/micro-metrics-datadog/src/test/java/com/aol/micro/server/datadog/metrics/DatadogMetricsConfigurerTest.java b/micro-metrics-datadog/src/test/java/com/oath/micro/server/datadog/metrics/DatadogMetricsConfigurerTest.java similarity index 97% rename from micro-metrics-datadog/src/test/java/com/aol/micro/server/datadog/metrics/DatadogMetricsConfigurerTest.java rename to micro-metrics-datadog/src/test/java/com/oath/micro/server/datadog/metrics/DatadogMetricsConfigurerTest.java index ed2177bed..c417dded5 100644 --- a/micro-metrics-datadog/src/test/java/com/aol/micro/server/datadog/metrics/DatadogMetricsConfigurerTest.java +++ b/micro-metrics-datadog/src/test/java/com/oath/micro/server/datadog/metrics/DatadogMetricsConfigurerTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.datadog.metrics; +package com.oath.micro.server.datadog.metrics; import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertThat; diff --git a/micro-metrics-datadog/src/test/java/com/oath/micro/server/testing/RestAgent.java b/micro-metrics-datadog/src/test/java/com/oath/micro/server/testing/RestAgent.java new file mode 100644 index 000000000..9eb341321 --- /dev/null +++ b/micro-metrics-datadog/src/test/java/com/oath/micro/server/testing/RestAgent.java @@ -0,0 +1,53 @@ +package com.oath.micro.server.testing; + +import com.oath.micro.server.rest.jackson.JacksonUtil; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.Invocation.Builder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; + +public class RestAgent { + + + public String getJson(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.get(String.class); + + } + + public String get(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.TEXT_PLAIN); + + return request.get(String.class); + + } + + public T post(String url, Object payload,Class type) { + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); + } + + +} diff --git a/micro-metrics/src/main/java/com/aol/micro/server/spring/metrics/MetricsPlugin.java b/micro-metrics/src/main/java/com/aol/micro/server/spring/metrics/MetricsPlugin.java deleted file mode 100644 index 1d154b0a2..000000000 --- a/micro-metrics/src/main/java/com/aol/micro/server/spring/metrics/MetricsPlugin.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.aol.micro.server.spring.metrics; - - -import com.aol.micro.server.Plugin; -import com.aol.micro.server.spring.metrics.health.HealthCheckRunner; -import com.aol.micro.server.spring.metrics.health.HealthResource; -import cyclops.collections.immutable.PersistentSetX; -import cyclops.collections.mutable.SetX; - -import java.util.Set; - -/** - * - * Collections of Spring configuration classes (Classes annotated with @Configuration) - * that configure various useful pieces of functionality - such as property file loading, - * datasources, scheduling etc - * - * @author johnmcclean - * - */ -public class MetricsPlugin implements Plugin { - - @Override - public Set springClasses() { - return SetX.of(CodahaleMetricsConfigurer.class, HealthCheckRunner.class, HealthResource.class); - } - -} diff --git a/micro-metrics/src/main/java/com/aol/micro/server/spring/metrics/CodahaleMetricsConfigurer.java b/micro-metrics/src/main/java/com/oath/micro/server/spring/metrics/CodahaleMetricsConfigurer.java similarity index 96% rename from micro-metrics/src/main/java/com/aol/micro/server/spring/metrics/CodahaleMetricsConfigurer.java rename to micro-metrics/src/main/java/com/oath/micro/server/spring/metrics/CodahaleMetricsConfigurer.java index 9fa3f5808..2d1fac173 100644 --- a/micro-metrics/src/main/java/com/aol/micro/server/spring/metrics/CodahaleMetricsConfigurer.java +++ b/micro-metrics/src/main/java/com/oath/micro/server/spring/metrics/CodahaleMetricsConfigurer.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.spring.metrics; +package com.oath.micro.server.spring.metrics; import java.util.concurrent.TimeUnit; import java.util.function.Consumer; diff --git a/micro-metrics/src/main/java/com/aol/micro/server/spring/metrics/InstantGauge.java b/micro-metrics/src/main/java/com/oath/micro/server/spring/metrics/InstantGauge.java similarity index 89% rename from micro-metrics/src/main/java/com/aol/micro/server/spring/metrics/InstantGauge.java rename to micro-metrics/src/main/java/com/oath/micro/server/spring/metrics/InstantGauge.java index 94f2f0192..6161860fb 100644 --- a/micro-metrics/src/main/java/com/aol/micro/server/spring/metrics/InstantGauge.java +++ b/micro-metrics/src/main/java/com/oath/micro/server/spring/metrics/InstantGauge.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.spring.metrics; +package com.oath.micro.server.spring.metrics; import java.util.concurrent.atomic.AtomicLong; diff --git a/micro-metrics/src/main/java/com/oath/micro/server/spring/metrics/MetricsPlugin.java b/micro-metrics/src/main/java/com/oath/micro/server/spring/metrics/MetricsPlugin.java new file mode 100644 index 000000000..dbf77a463 --- /dev/null +++ b/micro-metrics/src/main/java/com/oath/micro/server/spring/metrics/MetricsPlugin.java @@ -0,0 +1,27 @@ +package com.oath.micro.server.spring.metrics; + + +import com.oath.micro.server.Plugin; +import com.oath.micro.server.spring.metrics.health.HealthCheckRunner; +import com.oath.micro.server.spring.metrics.health.HealthResource; +import cyclops.collections.mutable.SetX; + +import java.util.Set; + +/** + * + * Collections of Spring configuration classes (Classes annotated with @Configuration) + * that configure various useful pieces of functionality - such as property file loading, + * datasources, scheduling etc + * + * @author johnmcclean + * + */ +public class MetricsPlugin implements Plugin { + + @Override + public Set springClasses() { + return SetX.of(CodahaleMetricsConfigurer.class, HealthCheckRunner.class, HealthResource.class); + } + +} diff --git a/micro-metrics/src/main/java/com/aol/micro/server/spring/metrics/health/HealthCheckRunner.java b/micro-metrics/src/main/java/com/oath/micro/server/spring/metrics/health/HealthCheckRunner.java similarity index 91% rename from micro-metrics/src/main/java/com/aol/micro/server/spring/metrics/health/HealthCheckRunner.java rename to micro-metrics/src/main/java/com/oath/micro/server/spring/metrics/health/HealthCheckRunner.java index 62491034a..df4bab8b2 100644 --- a/micro-metrics/src/main/java/com/aol/micro/server/spring/metrics/health/HealthCheckRunner.java +++ b/micro-metrics/src/main/java/com/oath/micro/server/spring/metrics/health/HealthCheckRunner.java @@ -1,11 +1,11 @@ -package com.aol.micro.server.spring.metrics.health; +package com.oath.micro.server.spring.metrics.health; import cyclops.companion.Semigroups; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; -import com.aol.micro.server.HealthStatusChecker; +import com.oath.micro.server.HealthStatusChecker; import com.codahale.metrics.health.HealthCheckRegistry; @Component diff --git a/micro-metrics/src/main/java/com/aol/micro/server/spring/metrics/health/HealthResource.java b/micro-metrics/src/main/java/com/oath/micro/server/spring/metrics/health/HealthResource.java similarity index 78% rename from micro-metrics/src/main/java/com/aol/micro/server/spring/metrics/health/HealthResource.java rename to micro-metrics/src/main/java/com/oath/micro/server/spring/metrics/health/HealthResource.java index 9a972a975..ddb6f5d43 100644 --- a/micro-metrics/src/main/java/com/aol/micro/server/spring/metrics/health/HealthResource.java +++ b/micro-metrics/src/main/java/com/oath/micro/server/spring/metrics/health/HealthResource.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.spring.metrics.health; +package com.oath.micro.server.spring.metrics.health; import java.util.Map; @@ -8,8 +8,8 @@ import org.springframework.stereotype.Component; -import com.aol.micro.server.auto.discovery.CommonRestResource; -import com.aol.micro.server.auto.discovery.SingletonRestResource; +import com.oath.micro.server.auto.discovery.CommonRestResource; +import com.oath.micro.server.auto.discovery.SingletonRestResource; import com.codahale.metrics.health.HealthCheck.Result; import com.codahale.metrics.health.HealthCheckRegistry; diff --git a/micro-metrics/src/main/resources/META-INF/services/com.aol.micro.server.Plugin b/micro-metrics/src/main/resources/META-INF/services/com.aol.micro.server.Plugin deleted file mode 100644 index a6b12afbb..000000000 --- a/micro-metrics/src/main/resources/META-INF/services/com.aol.micro.server.Plugin +++ /dev/null @@ -1 +0,0 @@ -com.aol.micro.server.spring.metrics.MetricsPlugin \ No newline at end of file diff --git a/micro-metrics/src/main/resources/META-INF/services/com.oath.micro.server.Plugin b/micro-metrics/src/main/resources/META-INF/services/com.oath.micro.server.Plugin new file mode 100644 index 000000000..cc5e4e6b0 --- /dev/null +++ b/micro-metrics/src/main/resources/META-INF/services/com.oath.micro.server.Plugin @@ -0,0 +1 @@ +com.oath.micro.server.spring.metrics.MetricsPlugin \ No newline at end of file diff --git a/micro-metrics/src/test/java/app/health/com/aol/micro/server/HealthTestResource.java b/micro-metrics/src/test/java/app/health/com/aol/micro/server/HealthTestResource.java deleted file mode 100644 index 389fb8b9f..000000000 --- a/micro-metrics/src/test/java/app/health/com/aol/micro/server/HealthTestResource.java +++ /dev/null @@ -1,25 +0,0 @@ -package app.health.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.beans.factory.annotation.Autowired; - -import com.aol.micro.server.HealthStatusChecker; -import com.aol.micro.server.auto.discovery.Rest; - -@Rest -@Path("/test") -public class HealthTestResource { - - @Autowired - HealthStatusChecker status; - - @GET - @Produces("text/plain") - public String health() { - return "" + status.isOk(); - - } -} diff --git a/micro-metrics/src/test/java/app/health/com/aol/micro/server/HealthRunnerTest.java b/micro-metrics/src/test/java/app/health/com/oath/micro/server/HealthRunnerTest.java similarity index 80% rename from micro-metrics/src/test/java/app/health/com/aol/micro/server/HealthRunnerTest.java rename to micro-metrics/src/test/java/app/health/com/oath/micro/server/HealthRunnerTest.java index 3a882b459..dc71a101a 100644 --- a/micro-metrics/src/test/java/app/health/com/aol/micro/server/HealthRunnerTest.java +++ b/micro-metrics/src/test/java/app/health/com/oath/micro/server/HealthRunnerTest.java @@ -1,4 +1,4 @@ -package app.health.com.aol.micro.server; +package app.health.com.oath.micro.server; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; @@ -13,14 +13,14 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.spring.metrics.CodahaleMetricsConfigurer; -import com.aol.micro.server.testing.RestAgent; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.spring.metrics.CodahaleMetricsConfigurer; +import com.oath.micro.server.testing.RestAgent; -import app.metrics.com.aol.micro.server.TestReporter; +import app.metrics.com.oath.micro.server.TestReporter; @Configuration -@ComponentScan(basePackages = { "app.metrics.com.aol.micro.server" }) +@ComponentScan(basePackages = { "app.metrics.com.oath.micro.server" }) public class HealthRunnerTest { RestAgent rest = new RestAgent(); diff --git a/micro-metrics/src/test/java/app/health/com/oath/micro/server/HealthTestResource.java b/micro-metrics/src/test/java/app/health/com/oath/micro/server/HealthTestResource.java new file mode 100644 index 000000000..139d8e3fd --- /dev/null +++ b/micro-metrics/src/test/java/app/health/com/oath/micro/server/HealthTestResource.java @@ -0,0 +1,25 @@ +package app.health.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.beans.factory.annotation.Autowired; + +import com.oath.micro.server.HealthStatusChecker; +import com.oath.micro.server.auto.discovery.Rest; + +@Rest +@Path("/test") +public class HealthTestResource { + + @Autowired + HealthStatusChecker status; + + @GET + @Produces("text/plain") + public String health() { + return "" + status.isOk(); + + } +} diff --git a/micro-metrics/src/test/java/app/health/com/aol/micro/server/MyHealthCheck.java b/micro-metrics/src/test/java/app/health/com/oath/micro/server/MyHealthCheck.java similarity index 86% rename from micro-metrics/src/test/java/app/health/com/aol/micro/server/MyHealthCheck.java rename to micro-metrics/src/test/java/app/health/com/oath/micro/server/MyHealthCheck.java index 8a2f188e3..f5d858ce4 100644 --- a/micro-metrics/src/test/java/app/health/com/aol/micro/server/MyHealthCheck.java +++ b/micro-metrics/src/test/java/app/health/com/oath/micro/server/MyHealthCheck.java @@ -1,4 +1,4 @@ -package app.health.com.aol.micro.server; +package app.health.com.oath.micro.server; import org.springframework.stereotype.Component; diff --git a/micro-metrics/src/test/java/app/metrics/com/aol/micro/server/MetricsRunnerTest.java b/micro-metrics/src/test/java/app/metrics/com/aol/micro/server/MetricsRunnerTest.java deleted file mode 100644 index 0fd8eea3a..000000000 --- a/micro-metrics/src/test/java/app/metrics/com/aol/micro/server/MetricsRunnerTest.java +++ /dev/null @@ -1,61 +0,0 @@ -package app.metrics.com.aol.micro.server; - - -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - -import java.io.IOException; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.spring.metrics.CodahaleMetricsConfigurer; -import com.aol.micro.server.testing.RestAgent; - -@Configuration -@ComponentScan(basePackages = { "app.metrics.com.aol.micro.server" }) -public class MetricsRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer(){ - CodahaleMetricsConfigurer.setInit( metricRegistry -> TestReporter - .forRegistry(metricRegistry) - .build() - .start(10, TimeUnit.MILLISECONDS)); - - server = new MicroserverApp( MetricsRunnerTest.class, ()-> "simple-app"); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException, IOException{ - - - - - - assertThat(rest.get("http://localhost:8080/simple-app/metrics/ping"),is("ok")); - - - assertThat(TestReporter.getTimer().size(),greaterThan(0)); - } - - - -} diff --git a/micro-metrics/src/test/java/app/metrics/com/aol/micro/server/MetricsStatusResource.java b/micro-metrics/src/test/java/app/metrics/com/aol/micro/server/MetricsStatusResource.java deleted file mode 100644 index de803313b..000000000 --- a/micro-metrics/src/test/java/app/metrics/com/aol/micro/server/MetricsStatusResource.java +++ /dev/null @@ -1,28 +0,0 @@ -package app.metrics.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import app.metrics.com.aol.micro.server.TimedResource; - -import com.aol.micro.server.auto.discovery.RestResource; - -@Component -@Path("/metrics") -public class MetricsStatusResource implements RestResource { - - @Autowired - TimedResource timed; - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - timed.times(); - return "ok"; - } - -} \ No newline at end of file diff --git a/micro-metrics/src/test/java/app/metrics/com/aol/micro/server/TestReporter.java b/micro-metrics/src/test/java/app/metrics/com/aol/micro/server/TestReporter.java deleted file mode 100644 index cfcf0136e..000000000 --- a/micro-metrics/src/test/java/app/metrics/com/aol/micro/server/TestReporter.java +++ /dev/null @@ -1,170 +0,0 @@ -package app.metrics.com.aol.micro.server; - -import java.io.PrintStream; -import java.util.Locale; -import java.util.SortedMap; -import java.util.TimeZone; -import java.util.TreeMap; -import java.util.concurrent.TimeUnit; - -import lombok.Getter; - -import com.codahale.metrics.Clock; -import com.codahale.metrics.ConsoleReporter; -import com.codahale.metrics.Counter; -import com.codahale.metrics.Gauge; -import com.codahale.metrics.Histogram; -import com.codahale.metrics.Meter; -import com.codahale.metrics.MetricFilter; -import com.codahale.metrics.MetricRegistry; -import com.codahale.metrics.ScheduledReporter; -import com.codahale.metrics.Timer; - - - -public class TestReporter extends ScheduledReporter { - - @Getter - private static volatile SortedMap timer = new TreeMap<>(); - - protected TestReporter(MetricRegistry registry, String name, - MetricFilter filter, TimeUnit rateUnit, TimeUnit durationUnit) { - super(registry, name, filter, rateUnit, durationUnit); - - } - - - public static Builder forRegistry(MetricRegistry registry) { - return new Builder(registry); - } - - @Override - public void report(SortedMap gauges, - SortedMap counters, - SortedMap histograms, - SortedMap meters, SortedMap timers) { - this.timer = timers; - - - } - - public static class Builder { - private final MetricRegistry registry; - private PrintStream output; - private Locale locale; - private Clock clock; - private TimeZone timeZone; - private TimeUnit rateUnit; - private TimeUnit durationUnit; - private MetricFilter filter; - - private Builder(MetricRegistry registry) { - this.registry = registry; - this.output = System.out; - this.locale = Locale.getDefault(); - this.clock = Clock.defaultClock(); - this.timeZone = TimeZone.getDefault(); - this.rateUnit = TimeUnit.SECONDS; - this.durationUnit = TimeUnit.MILLISECONDS; - this.filter = MetricFilter.ALL; - } - - /** - * Write to the given {@link PrintStream}. - * - * @param output a {@link PrintStream} instance. - * @return {@code this} - */ - public Builder outputTo(PrintStream output) { - this.output = output; - return this; - } - - /** - * Format numbers for the given {@link Locale}. - * - * @param locale a {@link Locale} - * @return {@code this} - */ - public Builder formattedFor(Locale locale) { - this.locale = locale; - return this; - } - - /** - * Use the given {@link Clock} instance for the time. - * - * @param clock a {@link Clock} instance - * @return {@code this} - */ - public Builder withClock(Clock clock) { - this.clock = clock; - return this; - } - - /** - * Use the given {@link TimeZone} for the time. - * - * @param timeZone a {@link TimeZone} - * @return {@code this} - */ - public Builder formattedFor(TimeZone timeZone) { - this.timeZone = timeZone; - return this; - } - - /** - * Convert rates to the given time unit. - * - * @param rateUnit a unit of time - * @return {@code this} - */ - public Builder convertRatesTo(TimeUnit rateUnit) { - this.rateUnit = rateUnit; - return this; - } - - /** - * Convert durations to the given time unit. - * - * @param durationUnit a unit of time - * @return {@code this} - */ - public Builder convertDurationsTo(TimeUnit durationUnit) { - this.durationUnit = durationUnit; - return this; - } - - /** - * Only report metrics which match the given filter. - * - * @param filter a {@link MetricFilter} - * @return {@code this} - */ - public Builder filter(MetricFilter filter) { - this.filter = filter; - return this; - } - - /** - * Builds a {@link ConsoleReporter} with the given properties. - * - * @return a {@link ConsoleReporter} - */ - public TestReporter build() { - return new TestReporter(registry, - // output, - "name", - // locale, - // clock, - // timeZone, - this.filter, - rateUnit, - durationUnit - ); - } - } - - -} - diff --git a/micro-metrics/src/test/java/app/metrics/com/aol/micro/server/TimedResource.java b/micro-metrics/src/test/java/app/metrics/com/aol/micro/server/TimedResource.java deleted file mode 100644 index a2e3f2910..000000000 --- a/micro-metrics/src/test/java/app/metrics/com/aol/micro/server/TimedResource.java +++ /dev/null @@ -1,17 +0,0 @@ -package app.metrics.com.aol.micro.server; - -import org.springframework.stereotype.Component; - -import com.codahale.metrics.annotation.Timed; -import com.ryantenney.metrics.annotation.Counted; - -@Component -public class TimedResource { - - - @Timed - public String times(){ - - return "ok!"; - } -} diff --git a/micro-metrics/src/test/java/app/metrics/com/oath/micro/server/MetricsRunnerTest.java b/micro-metrics/src/test/java/app/metrics/com/oath/micro/server/MetricsRunnerTest.java new file mode 100644 index 000000000..3a77bc3eb --- /dev/null +++ b/micro-metrics/src/test/java/app/metrics/com/oath/micro/server/MetricsRunnerTest.java @@ -0,0 +1,61 @@ +package app.metrics.com.oath.micro.server; + + +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + +import java.io.IOException; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.spring.metrics.CodahaleMetricsConfigurer; +import com.oath.micro.server.testing.RestAgent; + +@Configuration +@ComponentScan(basePackages = { "app.metrics.com.aol.micro.server" }) +public class MetricsRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer(){ + CodahaleMetricsConfigurer.setInit( metricRegistry -> TestReporter + .forRegistry(metricRegistry) + .build() + .start(10, TimeUnit.MILLISECONDS)); + + server = new MicroserverApp( MetricsRunnerTest.class, ()-> "simple-app"); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException, IOException{ + + + + + + assertThat(rest.get("http://localhost:8080/simple-app/metrics/ping"),is("ok")); + + + assertThat(TestReporter.getTimer().size(),greaterThan(0)); + } + + + +} diff --git a/micro-metrics/src/test/java/app/metrics/com/oath/micro/server/MetricsStatusResource.java b/micro-metrics/src/test/java/app/metrics/com/oath/micro/server/MetricsStatusResource.java new file mode 100644 index 000000000..3559c2590 --- /dev/null +++ b/micro-metrics/src/test/java/app/metrics/com/oath/micro/server/MetricsStatusResource.java @@ -0,0 +1,26 @@ +package app.metrics.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.RestResource; + +@Component +@Path("/metrics") +public class MetricsStatusResource implements RestResource { + + @Autowired + TimedResource timed; + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + timed.times(); + return "ok"; + } + +} \ No newline at end of file diff --git a/micro-metrics/src/test/java/app/metrics/com/oath/micro/server/TestReporter.java b/micro-metrics/src/test/java/app/metrics/com/oath/micro/server/TestReporter.java new file mode 100644 index 000000000..530782ee0 --- /dev/null +++ b/micro-metrics/src/test/java/app/metrics/com/oath/micro/server/TestReporter.java @@ -0,0 +1,170 @@ +package app.metrics.com.oath.micro.server; + +import java.io.PrintStream; +import java.util.Locale; +import java.util.SortedMap; +import java.util.TimeZone; +import java.util.TreeMap; +import java.util.concurrent.TimeUnit; + +import lombok.Getter; + +import com.codahale.metrics.Clock; +import com.codahale.metrics.ConsoleReporter; +import com.codahale.metrics.Counter; +import com.codahale.metrics.Gauge; +import com.codahale.metrics.Histogram; +import com.codahale.metrics.Meter; +import com.codahale.metrics.MetricFilter; +import com.codahale.metrics.MetricRegistry; +import com.codahale.metrics.ScheduledReporter; +import com.codahale.metrics.Timer; + + + +public class TestReporter extends ScheduledReporter { + + @Getter + private static volatile SortedMap timer = new TreeMap<>(); + + protected TestReporter(MetricRegistry registry, String name, + MetricFilter filter, TimeUnit rateUnit, TimeUnit durationUnit) { + super(registry, name, filter, rateUnit, durationUnit); + + } + + + public static Builder forRegistry(MetricRegistry registry) { + return new Builder(registry); + } + + @Override + public void report(SortedMap gauges, + SortedMap counters, + SortedMap histograms, + SortedMap meters, SortedMap timers) { + this.timer = timers; + + + } + + public static class Builder { + private final MetricRegistry registry; + private PrintStream output; + private Locale locale; + private Clock clock; + private TimeZone timeZone; + private TimeUnit rateUnit; + private TimeUnit durationUnit; + private MetricFilter filter; + + private Builder(MetricRegistry registry) { + this.registry = registry; + this.output = System.out; + this.locale = Locale.getDefault(); + this.clock = Clock.defaultClock(); + this.timeZone = TimeZone.getDefault(); + this.rateUnit = TimeUnit.SECONDS; + this.durationUnit = TimeUnit.MILLISECONDS; + this.filter = MetricFilter.ALL; + } + + /** + * Write to the given {@link PrintStream}. + * + * @param output a {@link PrintStream} instance. + * @return {@code this} + */ + public Builder outputTo(PrintStream output) { + this.output = output; + return this; + } + + /** + * Format numbers for the given {@link Locale}. + * + * @param locale a {@link Locale} + * @return {@code this} + */ + public Builder formattedFor(Locale locale) { + this.locale = locale; + return this; + } + + /** + * Use the given {@link Clock} instance for the time. + * + * @param clock a {@link Clock} instance + * @return {@code this} + */ + public Builder withClock(Clock clock) { + this.clock = clock; + return this; + } + + /** + * Use the given {@link TimeZone} for the time. + * + * @param timeZone a {@link TimeZone} + * @return {@code this} + */ + public Builder formattedFor(TimeZone timeZone) { + this.timeZone = timeZone; + return this; + } + + /** + * Convert rates to the given time unit. + * + * @param rateUnit a unit of time + * @return {@code this} + */ + public Builder convertRatesTo(TimeUnit rateUnit) { + this.rateUnit = rateUnit; + return this; + } + + /** + * Convert durations to the given time unit. + * + * @param durationUnit a unit of time + * @return {@code this} + */ + public Builder convertDurationsTo(TimeUnit durationUnit) { + this.durationUnit = durationUnit; + return this; + } + + /** + * Only report metrics which match the given filter. + * + * @param filter a {@link MetricFilter} + * @return {@code this} + */ + public Builder filter(MetricFilter filter) { + this.filter = filter; + return this; + } + + /** + * Builds a {@link ConsoleReporter} with the given properties. + * + * @return a {@link ConsoleReporter} + */ + public TestReporter build() { + return new TestReporter(registry, + // output, + "name", + // locale, + // clock, + // timeZone, + this.filter, + rateUnit, + durationUnit + ); + } + } + + +} + diff --git a/micro-metrics/src/test/java/app/metrics/com/oath/micro/server/TimedResource.java b/micro-metrics/src/test/java/app/metrics/com/oath/micro/server/TimedResource.java new file mode 100644 index 000000000..50626f343 --- /dev/null +++ b/micro-metrics/src/test/java/app/metrics/com/oath/micro/server/TimedResource.java @@ -0,0 +1,16 @@ +package app.metrics.com.oath.micro.server; + +import org.springframework.stereotype.Component; + +import com.codahale.metrics.annotation.Timed; + +@Component +public class TimedResource { + + + @Timed + public String times(){ + + return "ok!"; + } +} diff --git a/micro-metrics/src/test/java/com/aol/micro/server/testing/RestAgent.java b/micro-metrics/src/test/java/com/aol/micro/server/testing/RestAgent.java deleted file mode 100644 index ce204f810..000000000 --- a/micro-metrics/src/test/java/com/aol/micro/server/testing/RestAgent.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.aol.micro.server.testing; - -import java.util.List; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.Invocation.Builder; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; - -import com.aol.micro.server.rest.jackson.JacksonUtil; - -public class RestAgent { - - - public String getJson(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.get(String.class); - - } - - public String get(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.TEXT_PLAIN); - - return request.get(String.class); - - } - - public T post(String url, Object payload,Class type) { - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); - } - - -} diff --git a/micro-metrics/src/test/java/com/aol/micro/server/spring/metrics/InstantGaugeTest.java b/micro-metrics/src/test/java/com/oath/micro/server/spring/metrics/InstantGaugeTest.java similarity index 87% rename from micro-metrics/src/test/java/com/aol/micro/server/spring/metrics/InstantGaugeTest.java rename to micro-metrics/src/test/java/com/oath/micro/server/spring/metrics/InstantGaugeTest.java index 32be828d0..57246a0ba 100644 --- a/micro-metrics/src/test/java/com/aol/micro/server/spring/metrics/InstantGaugeTest.java +++ b/micro-metrics/src/test/java/com/oath/micro/server/spring/metrics/InstantGaugeTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.spring.metrics; +package com.oath.micro.server.spring.metrics; import org.junit.Test; import static org.junit.Assert.assertEquals; diff --git a/micro-metrics/src/test/java/com/oath/micro/server/testing/RestAgent.java b/micro-metrics/src/test/java/com/oath/micro/server/testing/RestAgent.java new file mode 100644 index 000000000..b2b86303e --- /dev/null +++ b/micro-metrics/src/test/java/com/oath/micro/server/testing/RestAgent.java @@ -0,0 +1,53 @@ +package com.oath.micro.server.testing; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.Invocation.Builder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; + +import com.oath.micro.server.rest.jackson.JacksonUtil; + +public class RestAgent { + + + public String getJson(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.get(String.class); + + } + + public String get(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.TEXT_PLAIN); + + return request.get(String.class); + + } + + public T post(String url, Object payload,Class type) { + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); + } + + +} diff --git a/micro-mysql/src/main/java/com/aol/micro/server/mysql/distlock/MySqlPlugin.java b/micro-mysql/src/main/java/com/aol/micro/server/mysql/distlock/MySqlPlugin.java deleted file mode 100644 index cf9cec839..000000000 --- a/micro-mysql/src/main/java/com/aol/micro/server/mysql/distlock/MySqlPlugin.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.aol.micro.server.mysql.distlock; - - -import com.aol.micro.server.Plugin; -import com.aol.micro.server.mysql.distlock.datasource.JdbcConfigDistLock; -import com.aol.micro.server.mysql.distlock.datasource.MysqlDataSourceBuilder; -import cyclops.collections.immutable.PersistentSetX; -import cyclops.collections.mutable.SetX; - -import java.util.Set; - -public class MySqlPlugin implements Plugin { - public Set springClasses(){ - return SetX.of(DistributedLockServiceMySqlImpl.class, - MysqlDataSourceBuilder.class,JdbcConfigDistLock.class); - } -} diff --git a/micro-mysql/src/main/java/com/aol/micro/server/mysql/distlock/DistributedLockServiceMySqlImpl.java b/micro-mysql/src/main/java/com/oath/micro/server/mysql/distlock/DistributedLockServiceMySqlImpl.java similarity index 93% rename from micro-mysql/src/main/java/com/aol/micro/server/mysql/distlock/DistributedLockServiceMySqlImpl.java rename to micro-mysql/src/main/java/com/oath/micro/server/mysql/distlock/DistributedLockServiceMySqlImpl.java index 1b639af96..ee810ecbb 100644 --- a/micro-mysql/src/main/java/com/aol/micro/server/mysql/distlock/DistributedLockServiceMySqlImpl.java +++ b/micro-mysql/src/main/java/com/oath/micro/server/mysql/distlock/DistributedLockServiceMySqlImpl.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.mysql.distlock; +package com.oath.micro.server.mysql.distlock; import javax.sql.DataSource; @@ -7,7 +7,7 @@ import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Component; -import com.aol.micro.server.dist.lock.DistributedLockService; +import com.oath.micro.server.dist.lock.DistributedLockService; @Component public class DistributedLockServiceMySqlImpl implements DistributedLockService { diff --git a/micro-mysql/src/main/java/com/oath/micro/server/mysql/distlock/MySqlPlugin.java b/micro-mysql/src/main/java/com/oath/micro/server/mysql/distlock/MySqlPlugin.java new file mode 100644 index 000000000..a4a0399a3 --- /dev/null +++ b/micro-mysql/src/main/java/com/oath/micro/server/mysql/distlock/MySqlPlugin.java @@ -0,0 +1,16 @@ +package com.oath.micro.server.mysql.distlock; + + +import com.oath.micro.server.Plugin; +import com.oath.micro.server.mysql.distlock.datasource.JdbcConfigDistLock; +import com.oath.micro.server.mysql.distlock.datasource.MysqlDataSourceBuilder; +import cyclops.collections.mutable.SetX; + +import java.util.Set; + +public class MySqlPlugin implements Plugin { + public Set springClasses(){ + return SetX.of(DistributedLockServiceMySqlImpl.class, + MysqlDataSourceBuilder.class,JdbcConfigDistLock.class); + } +} diff --git a/micro-mysql/src/main/java/com/aol/micro/server/mysql/distlock/datasource/JdbcConfigDistLock.java b/micro-mysql/src/main/java/com/oath/micro/server/mysql/distlock/datasource/JdbcConfigDistLock.java similarity index 96% rename from micro-mysql/src/main/java/com/aol/micro/server/mysql/distlock/datasource/JdbcConfigDistLock.java rename to micro-mysql/src/main/java/com/oath/micro/server/mysql/distlock/datasource/JdbcConfigDistLock.java index 1d9de18e4..93e926b66 100644 --- a/micro-mysql/src/main/java/com/aol/micro/server/mysql/distlock/datasource/JdbcConfigDistLock.java +++ b/micro-mysql/src/main/java/com/oath/micro/server/mysql/distlock/datasource/JdbcConfigDistLock.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.mysql.distlock.datasource; +package com.oath.micro.server.mysql.distlock.datasource; import java.util.Properties; diff --git a/micro-mysql/src/main/java/com/aol/micro/server/mysql/distlock/datasource/MysqlDataSourceBuilder.java b/micro-mysql/src/main/java/com/oath/micro/server/mysql/distlock/datasource/MysqlDataSourceBuilder.java similarity index 94% rename from micro-mysql/src/main/java/com/aol/micro/server/mysql/distlock/datasource/MysqlDataSourceBuilder.java rename to micro-mysql/src/main/java/com/oath/micro/server/mysql/distlock/datasource/MysqlDataSourceBuilder.java index 39fa05f24..47890f896 100644 --- a/micro-mysql/src/main/java/com/aol/micro/server/mysql/distlock/datasource/MysqlDataSourceBuilder.java +++ b/micro-mysql/src/main/java/com/oath/micro/server/mysql/distlock/datasource/MysqlDataSourceBuilder.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.mysql.distlock.datasource; +package com.oath.micro.server.mysql.distlock.datasource; import javax.annotation.Resource; import javax.sql.DataSource; diff --git a/micro-mysql/src/main/resources/META-INF/services/com.aol.micro.server.Plugin b/micro-mysql/src/main/resources/META-INF/services/com.aol.micro.server.Plugin deleted file mode 100644 index d7e909829..000000000 --- a/micro-mysql/src/main/resources/META-INF/services/com.aol.micro.server.Plugin +++ /dev/null @@ -1 +0,0 @@ -com.aol.micro.server.mysql.distlock.MySqlPlugin \ No newline at end of file diff --git a/micro-mysql/src/main/resources/META-INF/services/com.oath.micro.server.Plugin b/micro-mysql/src/main/resources/META-INF/services/com.oath.micro.server.Plugin new file mode 100644 index 000000000..456a38736 --- /dev/null +++ b/micro-mysql/src/main/resources/META-INF/services/com.oath.micro.server.Plugin @@ -0,0 +1 @@ +com.oath.micro.server.mysql.distlock.MySqlPlugin \ No newline at end of file diff --git a/micro-mysql/src/test/java/app/single/com/aol/micro/server/SimpleClassTest.java b/micro-mysql/src/test/java/app/single/com/aol/micro/server/SimpleClassTest.java deleted file mode 100644 index 27ac50359..000000000 --- a/micro-mysql/src/test/java/app/single/com/aol/micro/server/SimpleClassTest.java +++ /dev/null @@ -1,60 +0,0 @@ -package app.single.com.aol.micro.server; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.RestResource; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.mysql.distlock.DistributedLockServiceMySqlImpl; -import com.aol.micro.server.testing.RestAgent; - -@Microserver(properties={"db.connection.driver","org.hsqldb.jdbcDriver", - "db.connection.url","jdbc:hsqldb:mem:aname", - "db.connection.username", "sa", - "db.connection.password", "", - "db.connection.dialect","org.hibernate.dialect.HSQLDialect", - "db.connection.ddl.auto","create-drop" }) -public class SimpleClassTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - - @Before - public void startServer(){ - - server = new MicroserverApp(()-> "simple-app"); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - assertThat(rest.get("http://localhost:8080/simple-app/status/ping"),is("true")); - - } - - - - -} \ No newline at end of file diff --git a/micro-mysql/src/test/java/app/single/com/aol/micro/server/SimpleStatusResource.java b/micro-mysql/src/test/java/app/single/com/aol/micro/server/SimpleStatusResource.java deleted file mode 100644 index 09ec9b576..000000000 --- a/micro-mysql/src/test/java/app/single/com/aol/micro/server/SimpleStatusResource.java +++ /dev/null @@ -1,36 +0,0 @@ -package app.single.com.aol.micro.server; - -import java.io.InputStream; - -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; - -import org.glassfish.jersey.media.multipart.FormDataContentDisposition; -import org.glassfish.jersey.media.multipart.FormDataParam; -import org.springframework.beans.factory.annotation.Autowired; - -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.mysql.distlock.DistributedLockServiceMySqlImpl; - -@Rest -@Path("/status") -public class SimpleStatusResource { - @Autowired - DistributedLockServiceMySqlImpl lock; - - - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - - return ""+ (lock!=null); - } - - -} \ No newline at end of file diff --git a/micro-mysql/src/test/java/app/single/com/oath/micro/server/SimpleClassTest.java b/micro-mysql/src/test/java/app/single/com/oath/micro/server/SimpleClassTest.java new file mode 100644 index 000000000..59268f26f --- /dev/null +++ b/micro-mysql/src/test/java/app/single/com/oath/micro/server/SimpleClassTest.java @@ -0,0 +1,52 @@ +package app.single.com.oath.micro.server; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.testing.RestAgent; + +@Microserver(properties={"db.connection.driver","org.hsqldb.jdbcDriver", + "db.connection.url","jdbc:hsqldb:mem:aname", + "db.connection.username", "sa", + "db.connection.password", "", + "db.connection.dialect","org.hibernate.dialect.HSQLDialect", + "db.connection.ddl.auto","create-drop" }) +public class SimpleClassTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + + @Before + public void startServer(){ + + server = new MicroserverApp(()-> "simple-app"); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + assertThat(rest.get("http://localhost:8080/simple-app/status/ping"),is("true")); + + } + + + + +} \ No newline at end of file diff --git a/micro-mysql/src/test/java/app/single/com/oath/micro/server/SimpleStatusResource.java b/micro-mysql/src/test/java/app/single/com/oath/micro/server/SimpleStatusResource.java new file mode 100644 index 000000000..d69d7c4a8 --- /dev/null +++ b/micro-mysql/src/test/java/app/single/com/oath/micro/server/SimpleStatusResource.java @@ -0,0 +1,29 @@ +package app.single.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.beans.factory.annotation.Autowired; + +import com.oath.micro.server.auto.discovery.Rest; +import com.oath.micro.server.mysql.distlock.DistributedLockServiceMySqlImpl; + +@Rest +@Path("/status") +public class SimpleStatusResource { + @Autowired + DistributedLockServiceMySqlImpl lock; + + + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + + return ""+ (lock!=null); + } + + +} \ No newline at end of file diff --git a/micro-mysql/src/test/java/com/aol/micro/server/testing/RestAgent.java b/micro-mysql/src/test/java/com/aol/micro/server/testing/RestAgent.java deleted file mode 100644 index ce204f810..000000000 --- a/micro-mysql/src/test/java/com/aol/micro/server/testing/RestAgent.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.aol.micro.server.testing; - -import java.util.List; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.Invocation.Builder; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; - -import com.aol.micro.server.rest.jackson.JacksonUtil; - -public class RestAgent { - - - public String getJson(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.get(String.class); - - } - - public String get(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.TEXT_PLAIN); - - return request.get(String.class); - - } - - public T post(String url, Object payload,Class type) { - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); - } - - -} diff --git a/micro-mysql/src/test/java/com/aol/micro/server/mysql/distlock/DistributedLockServiceConfigurationTest.groovy b/micro-mysql/src/test/java/com/oath/micro/server/mysql/distlock/DistributedLockServiceConfigurationTest.groovy similarity index 94% rename from micro-mysql/src/test/java/com/aol/micro/server/mysql/distlock/DistributedLockServiceConfigurationTest.groovy rename to micro-mysql/src/test/java/com/oath/micro/server/mysql/distlock/DistributedLockServiceConfigurationTest.groovy index 9739f8ce7..399224805 100644 --- a/micro-mysql/src/test/java/com/aol/micro/server/mysql/distlock/DistributedLockServiceConfigurationTest.groovy +++ b/micro-mysql/src/test/java/com/oath/micro/server/mysql/distlock/DistributedLockServiceConfigurationTest.groovy @@ -1,4 +1,4 @@ -package com.aol.micro.server.mysql.distlock +package com.oath.micro.server.mysql.distlock import static org.hamcrest.CoreMatchers.is import static org.junit.Assert.assertThat diff --git a/micro-mysql/src/test/java/com/aol/micro/server/mysql/distlock/DistributedLockServiceMySqlImplTest.java b/micro-mysql/src/test/java/com/oath/micro/server/mysql/distlock/DistributedLockServiceMySqlImplTest.java similarity index 98% rename from micro-mysql/src/test/java/com/aol/micro/server/mysql/distlock/DistributedLockServiceMySqlImplTest.java rename to micro-mysql/src/test/java/com/oath/micro/server/mysql/distlock/DistributedLockServiceMySqlImplTest.java index e86911cd9..62bc30a88 100644 --- a/micro-mysql/src/test/java/com/aol/micro/server/mysql/distlock/DistributedLockServiceMySqlImplTest.java +++ b/micro-mysql/src/test/java/com/oath/micro/server/mysql/distlock/DistributedLockServiceMySqlImplTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.mysql.distlock; +package com.oath.micro.server.mysql.distlock; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.not; diff --git a/micro-mysql/src/test/java/com/oath/micro/server/testing/RestAgent.java b/micro-mysql/src/test/java/com/oath/micro/server/testing/RestAgent.java new file mode 100644 index 000000000..b2b86303e --- /dev/null +++ b/micro-mysql/src/test/java/com/oath/micro/server/testing/RestAgent.java @@ -0,0 +1,53 @@ +package com.oath.micro.server.testing; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.Invocation.Builder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; + +import com.oath.micro.server.rest.jackson.JacksonUtil; + +public class RestAgent { + + + public String getJson(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.get(String.class); + + } + + public String get(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.TEXT_PLAIN); + + return request.get(String.class); + + } + + public T post(String url, Object payload,Class type) { + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); + } + + +} diff --git a/micro-reactive/src/main/java/com/aol/micro/server/reactive/ReactivePlugin.java b/micro-reactive/src/main/java/com/aol/micro/server/reactive/ReactivePlugin.java deleted file mode 100644 index 680c390ea..000000000 --- a/micro-reactive/src/main/java/com/aol/micro/server/reactive/ReactivePlugin.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.aol.micro.server.reactive; - - -import com.aol.micro.server.Plugin; -import cyclops.collections.immutable.PersistentSetX; -import cyclops.collections.mutable.SetX; - -import java.util.Set; - - -public class ReactivePlugin implements Plugin{ - - - - -} diff --git a/micro-reactive/src/main/java/com/aol/micro/server/reactive/JobSchedular.java b/micro-reactive/src/main/java/com/oath/micro/server/reactive/JobSchedular.java similarity index 87% rename from micro-reactive/src/main/java/com/aol/micro/server/reactive/JobSchedular.java rename to micro-reactive/src/main/java/com/oath/micro/server/reactive/JobSchedular.java index f27e91b7e..d8bbd904d 100644 --- a/micro-reactive/src/main/java/com/aol/micro/server/reactive/JobSchedular.java +++ b/micro-reactive/src/main/java/com/oath/micro/server/reactive/JobSchedular.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.reactive; +package com.oath.micro.server.reactive; import java.util.concurrent.ScheduledExecutorService; import com.oath.cyclops.types.stream.HotStream; @@ -6,8 +6,8 @@ import lombok.AllArgsConstructor; -import com.aol.micro.server.events.ScheduledJob; -import com.aol.micro.server.events.SystemData; +import com.oath.micro.server.events.ScheduledJob; +import com.oath.micro.server.events.SystemData; @AllArgsConstructor public class JobSchedular { diff --git a/micro-reactive/src/main/java/com/oath/micro/server/reactive/ReactivePlugin.java b/micro-reactive/src/main/java/com/oath/micro/server/reactive/ReactivePlugin.java new file mode 100644 index 000000000..a07ba59e4 --- /dev/null +++ b/micro-reactive/src/main/java/com/oath/micro/server/reactive/ReactivePlugin.java @@ -0,0 +1,12 @@ +package com.oath.micro.server.reactive; + + +import com.oath.micro.server.Plugin; + + +public class ReactivePlugin implements Plugin{ + + + + +} diff --git a/micro-reactive/src/main/java/com/aol/micro/server/reactive/rest/ReactiveRequest.java b/micro-reactive/src/main/java/com/oath/micro/server/reactive/rest/ReactiveRequest.java similarity index 97% rename from micro-reactive/src/main/java/com/aol/micro/server/reactive/rest/ReactiveRequest.java rename to micro-reactive/src/main/java/com/oath/micro/server/reactive/rest/ReactiveRequest.java index e5105f88d..61aff51fc 100644 --- a/micro-reactive/src/main/java/com/aol/micro/server/reactive/rest/ReactiveRequest.java +++ b/micro-reactive/src/main/java/com/oath/micro/server/reactive/rest/ReactiveRequest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.reactive.rest; +package com.oath.micro.server.reactive.rest; import java.io.BufferedReader; import java.io.InputStream; @@ -15,8 +15,8 @@ import org.glassfish.jersey.client.ClientProperties; -import com.aol.micro.server.rest.jackson.JacksonFeature; -import com.aol.micro.server.rest.jackson.JacksonUtil; +import com.oath.micro.server.rest.jackson.JacksonFeature; +import com.oath.micro.server.rest.jackson.JacksonUtil; import com.fasterxml.jackson.databind.JavaType; import lombok.AllArgsConstructor; diff --git a/micro-reactive/src/main/java/com/aol/micro/server/reactive/rest/ReactiveResponse.java b/micro-reactive/src/main/java/com/oath/micro/server/reactive/rest/ReactiveResponse.java similarity index 93% rename from micro-reactive/src/main/java/com/aol/micro/server/reactive/rest/ReactiveResponse.java rename to micro-reactive/src/main/java/com/oath/micro/server/reactive/rest/ReactiveResponse.java index 99cb1a801..5dc3511c8 100644 --- a/micro-reactive/src/main/java/com/aol/micro/server/reactive/rest/ReactiveResponse.java +++ b/micro-reactive/src/main/java/com/oath/micro/server/reactive/rest/ReactiveResponse.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.reactive.rest; +package com.oath.micro.server.reactive.rest; import java.io.BufferedWriter; import java.io.IOException; @@ -16,7 +16,7 @@ import org.reactivestreams.Publisher; -import com.aol.micro.server.rest.jackson.JacksonUtil; +import com.oath.micro.server.rest.jackson.JacksonUtil; public class ReactiveResponse { diff --git a/micro-reactive/src/main/resources/META-INF/services/com.aol.micro.server.Plugin b/micro-reactive/src/main/resources/META-INF/services/com.aol.micro.server.Plugin deleted file mode 100644 index aaf0778ee..000000000 --- a/micro-reactive/src/main/resources/META-INF/services/com.aol.micro.server.Plugin +++ /dev/null @@ -1 +0,0 @@ -com.aol.micro.server.reactive.ReactivePlugin \ No newline at end of file diff --git a/micro-reactive/src/main/resources/META-INF/services/com.oath.micro.server.Plugin b/micro-reactive/src/main/resources/META-INF/services/com.oath.micro.server.Plugin new file mode 100644 index 000000000..ac0e2a888 --- /dev/null +++ b/micro-reactive/src/main/resources/META-INF/services/com.oath.micro.server.Plugin @@ -0,0 +1 @@ +com.oath.micro.server.reactive.ReactivePlugin \ No newline at end of file diff --git a/micro-reactive/src/test/java/app/async/com/aol/micro/server/AsyncAppRunner.java b/micro-reactive/src/test/java/app/async/com/aol/micro/server/AsyncAppRunner.java deleted file mode 100644 index 979b5fbf5..000000000 --- a/micro-reactive/src/test/java/app/async/com/aol/micro/server/AsyncAppRunner.java +++ /dev/null @@ -1,57 +0,0 @@ -package app.async.com.aol.micro.server; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.io.IOException; -import java.util.Properties; -import java.util.concurrent.ExecutionException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.spring.properties.PropertyFileConfig; -import com.aol.micro.server.testing.RestAgent; - -@Microserver -public class AsyncAppRunner { - - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer(){ - - server = new MicroserverApp( ()-> "async-app"); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - Thread.sleep(2000); - - assertThat(rest.get("http://localhost:8080/async-app/async/expensive"),is(";test!;test!;test!")); - - } - - @Test - public void loadProperties() throws IOException{ - - Properties props = new PropertyFileConfig(true).propertyFactory() ; - assertThat(props.getProperty("test"),is("hello world")); - } - - - -} \ No newline at end of file diff --git a/micro-reactive/src/test/java/app/async/com/aol/micro/server/AsyncResource.java b/micro-reactive/src/test/java/app/async/com/aol/micro/server/AsyncResource.java deleted file mode 100644 index be75bd523..000000000 --- a/micro-reactive/src/test/java/app/async/com/aol/micro/server/AsyncResource.java +++ /dev/null @@ -1,58 +0,0 @@ -package app.async.com.aol.micro.server; - -import java.util.Arrays; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.container.AsyncResponse; -import javax.ws.rs.container.Suspended; - -import cyclops.async.SimpleReact; -import cyclops.data.Seq; -import cyclops.reactive.FutureStream; -import cyclops.reactive.ReactiveSeq; - -import org.springframework.stereotype.Component; - - -import com.aol.micro.server.auto.discovery.RestResource; -import com.aol.micro.server.testing.RestAgent; - -@Path("/async") -@Component -public class AsyncResource implements RestResource{ - - private final SimpleReact simpleReact =new SimpleReact(); - private final Seq urls = Seq.fromIterable(Arrays.asList("http://localhost:8080/async-app/async/ping2", - "http://localhost:8080/async-app/async/ping", - "http://localhost:8080/async-app/async/ping", - "http://localhost:8080/async-app/async/ping")); - - private final RestAgent client = new RestAgent(); - - @GET - @Path("/expensive") - @Produces("text/plain") - public void expensive(@Suspended AsyncResponse asyncResponse){ - - FutureStream.builder().fromIterable(urls) - .then(it->client.get(it)) - .onFail(it -> "") - .peek(it -> - System.out.println(it)) - .convertToSimpleReact() - .allOf(data -> { - System.out.println(data); - return asyncResponse.resume(ReactiveSeq.fromIterable(data).join(";")); }); - } - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "test!"; - } - - -} diff --git a/micro-reactive/src/test/java/app/async/com/aol/micro/server/Simple.java b/micro-reactive/src/test/java/app/async/com/aol/micro/server/Simple.java deleted file mode 100644 index edefa80ef..000000000 --- a/micro-reactive/src/test/java/app/async/com/aol/micro/server/Simple.java +++ /dev/null @@ -1,16 +0,0 @@ -package app.async.com.aol.micro.server; - -import java.io.IOException; -import java.util.Properties; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Config; -import com.aol.micro.server.spring.properties.PropertyFileConfig; - -public class Simple { - - public static void main(String[] args) throws IOException{ - - new MicroserverApp(()->"test-app").run(); - } -} diff --git a/micro-reactive/src/test/java/app/async/com/aol/micro/server/SimpleApp.java b/micro-reactive/src/test/java/app/async/com/aol/micro/server/SimpleApp.java deleted file mode 100644 index 919b7c6b0..000000000 --- a/micro-reactive/src/test/java/app/async/com/aol/micro/server/SimpleApp.java +++ /dev/null @@ -1,24 +0,0 @@ -package app.async.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.Rest; - - - -@Rest -@Path("/test") -public class SimpleApp { - - public static void main(String[] args){ - new MicroserverApp(()->"test-app").run(); - } - @GET - public String myEndPoint(){ - return "hello world!"; - } - - -} diff --git a/micro-reactive/src/test/java/app/async/com/oath/micro/server/AsyncAppRunner.java b/micro-reactive/src/test/java/app/async/com/oath/micro/server/AsyncAppRunner.java new file mode 100644 index 000000000..c71dd8184 --- /dev/null +++ b/micro-reactive/src/test/java/app/async/com/oath/micro/server/AsyncAppRunner.java @@ -0,0 +1,57 @@ +package app.async.com.oath.micro.server; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.io.IOException; +import java.util.Properties; +import java.util.concurrent.ExecutionException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.spring.properties.PropertyFileConfig; +import com.oath.micro.server.testing.RestAgent; + +@Microserver +public class AsyncAppRunner { + + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer(){ + + server = new MicroserverApp( ()-> "async-app"); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + Thread.sleep(2000); + + assertThat(rest.get("http://localhost:8080/async-app/async/expensive"),is(";test!;test!;test!")); + + } + + @Test + public void loadProperties() throws IOException{ + + Properties props = new PropertyFileConfig(true).propertyFactory() ; + assertThat(props.getProperty("test"),is("hello world")); + } + + + +} \ No newline at end of file diff --git a/micro-reactive/src/test/java/app/async/com/oath/micro/server/AsyncResource.java b/micro-reactive/src/test/java/app/async/com/oath/micro/server/AsyncResource.java new file mode 100644 index 000000000..7043671d1 --- /dev/null +++ b/micro-reactive/src/test/java/app/async/com/oath/micro/server/AsyncResource.java @@ -0,0 +1,58 @@ +package app.async.com.oath.micro.server; + +import java.util.Arrays; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.container.AsyncResponse; +import javax.ws.rs.container.Suspended; + +import cyclops.async.SimpleReact; +import cyclops.data.Seq; +import cyclops.reactive.FutureStream; +import cyclops.reactive.ReactiveSeq; + +import org.springframework.stereotype.Component; + + +import com.oath.micro.server.auto.discovery.RestResource; +import com.oath.micro.server.testing.RestAgent; + +@Path("/async") +@Component +public class AsyncResource implements RestResource{ + + private final SimpleReact simpleReact =new SimpleReact(); + private final Seq urls = Seq.fromIterable(Arrays.asList("http://localhost:8080/async-app/async/ping2", + "http://localhost:8080/async-app/async/ping", + "http://localhost:8080/async-app/async/ping", + "http://localhost:8080/async-app/async/ping")); + + private final RestAgent client = new RestAgent(); + + @GET + @Path("/expensive") + @Produces("text/plain") + public void expensive(@Suspended AsyncResponse asyncResponse){ + + FutureStream.builder().fromIterable(urls) + .then(it->client.get(it)) + .onFail(it -> "") + .peek(it -> + System.out.println(it)) + .convertToSimpleReact() + .allOf(data -> { + System.out.println(data); + return asyncResponse.resume(ReactiveSeq.fromIterable(data).join(";")); }); + } + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "test!"; + } + + +} diff --git a/micro-reactive/src/test/java/app/async/com/oath/micro/server/Simple.java b/micro-reactive/src/test/java/app/async/com/oath/micro/server/Simple.java new file mode 100644 index 000000000..3eb3e7504 --- /dev/null +++ b/micro-reactive/src/test/java/app/async/com/oath/micro/server/Simple.java @@ -0,0 +1,13 @@ +package app.async.com.oath.micro.server; + +import java.io.IOException; + +import com.oath.micro.server.MicroserverApp; + +public class Simple { + + public static void main(String[] args) throws IOException{ + + new MicroserverApp(()->"test-app").run(); + } +} diff --git a/micro-reactive/src/test/java/app/async/com/oath/micro/server/SimpleApp.java b/micro-reactive/src/test/java/app/async/com/oath/micro/server/SimpleApp.java new file mode 100644 index 000000000..916d0330e --- /dev/null +++ b/micro-reactive/src/test/java/app/async/com/oath/micro/server/SimpleApp.java @@ -0,0 +1,24 @@ +package app.async.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.auto.discovery.Rest; + + + +@Rest +@Path("/test") +public class SimpleApp { + + public static void main(String[] args){ + new MicroserverApp(()->"test-app").run(); + } + @GET + public String myEndPoint(){ + return "hello world!"; + } + + +} diff --git a/micro-reactive/src/test/java/app/bus/com/aol/micro/server/SingleClassTest.java b/micro-reactive/src/test/java/app/bus/com/aol/micro/server/SingleClassTest.java index 7dbddeab7..6f25c6a29 100644 --- a/micro-reactive/src/test/java/app/bus/com/aol/micro/server/SingleClassTest.java +++ b/micro-reactive/src/test/java/app/bus/com/aol/micro/server/SingleClassTest.java @@ -1,12 +1,10 @@ package app.bus.com.aol.micro.server; -import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; import java.util.concurrent.ExecutionException; -import javax.annotation.PostConstruct; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; @@ -14,12 +12,11 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.RestResource; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.testing.RestAgent; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.auto.discovery.RestResource; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.testing.RestAgent; @Microserver @Path("/single") diff --git a/micro-reactive/src/test/java/app/streaming/com/aol/micro/server/SingleClassTest.java b/micro-reactive/src/test/java/app/streaming/com/aol/micro/server/SingleClassTest.java index 8e92e5586..9a76f3861 100644 --- a/micro-reactive/src/test/java/app/streaming/com/aol/micro/server/SingleClassTest.java +++ b/micro-reactive/src/test/java/app/streaming/com/aol/micro/server/SingleClassTest.java @@ -11,7 +11,6 @@ import java.util.List; import java.util.concurrent.ExecutionException; -import javax.annotation.PostConstruct; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; @@ -24,15 +23,14 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.RestResource; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.reactive.rest.ReactiveRequest; -import com.aol.micro.server.reactive.rest.ReactiveResponse; -import com.aol.micro.server.testing.RestAgent; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.auto.discovery.RestResource; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.reactive.rest.ReactiveRequest; +import com.oath.micro.server.reactive.rest.ReactiveResponse; +import com.oath.micro.server.testing.RestAgent; @Microserver @Path("/single") diff --git a/micro-reactive/src/test/java/com/aol/micro/server/testing/RestAgent.java b/micro-reactive/src/test/java/com/aol/micro/server/testing/RestAgent.java deleted file mode 100644 index ce204f810..000000000 --- a/micro-reactive/src/test/java/com/aol/micro/server/testing/RestAgent.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.aol.micro.server.testing; - -import java.util.List; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.Invocation.Builder; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; - -import com.aol.micro.server.rest.jackson.JacksonUtil; - -public class RestAgent { - - - public String getJson(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.get(String.class); - - } - - public String get(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.TEXT_PLAIN); - - return request.get(String.class); - - } - - public T post(String url, Object payload,Class type) { - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); - } - - -} diff --git a/micro-reactive/src/test/java/com/aol/micro/server/reactive/ScheduledJobTest.java b/micro-reactive/src/test/java/com/oath/micro/server/reactive/ScheduledJobTest.java similarity index 91% rename from micro-reactive/src/test/java/com/aol/micro/server/reactive/ScheduledJobTest.java rename to micro-reactive/src/test/java/com/oath/micro/server/reactive/ScheduledJobTest.java index 87e797187..78b779ab2 100644 --- a/micro-reactive/src/test/java/com/aol/micro/server/reactive/ScheduledJobTest.java +++ b/micro-reactive/src/test/java/com/oath/micro/server/reactive/ScheduledJobTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.reactive; +package com.oath.micro.server.reactive; import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertThat; @@ -10,8 +10,8 @@ import org.junit.Test; -import com.aol.micro.server.events.ScheduledJob; -import com.aol.micro.server.events.SystemData; +import com.oath.micro.server.events.ScheduledJob; +import com.oath.micro.server.events.SystemData; public class ScheduledJobTest { diff --git a/micro-reactive/src/test/java/com/oath/micro/server/testing/RestAgent.java b/micro-reactive/src/test/java/com/oath/micro/server/testing/RestAgent.java new file mode 100644 index 000000000..b2b86303e --- /dev/null +++ b/micro-reactive/src/test/java/com/oath/micro/server/testing/RestAgent.java @@ -0,0 +1,53 @@ +package com.oath.micro.server.testing; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.Invocation.Builder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; + +import com.oath.micro.server.rest.jackson.JacksonUtil; + +public class RestAgent { + + + public String getJson(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.get(String.class); + + } + + public String get(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.TEXT_PLAIN); + + return request.get(String.class); + + } + + public T post(String url, Object payload,Class type) { + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); + } + + +} diff --git a/micro-s3/src/main/java/com/aol/micro/server/s3/plugin/S3Plugin.java b/micro-s3/src/main/java/com/aol/micro/server/s3/plugin/S3Plugin.java deleted file mode 100644 index 9fb6ee4f1..000000000 --- a/micro-s3/src/main/java/com/aol/micro/server/s3/plugin/S3Plugin.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.aol.micro.server.s3.plugin; - - -import com.aol.micro.server.Plugin; -import com.aol.micro.server.s3.DirectoryCleaner; -import com.aol.micro.server.s3.S3Configuration; -import com.aol.micro.server.s3.data.S3DistributedMapClient; -import com.aol.micro.server.s3.data.S3Utils; -import cyclops.collections.immutable.PersistentSetX; -import cyclops.collections.mutable.SetX; - -import java.util.Set; - -public class S3Plugin implements Plugin { - - @Override - public Set springClasses() { - return SetX.of(S3ManifestComparatorProvider.class, S3DistributedMapClient.class, S3Configuration.class, - S3ClientProvider.class, S3Utils.class, S3TransferManagerProvider.class, DirectoryCleaner.class); - } - -} diff --git a/micro-s3/src/main/java/com/aol/micro/server/s3/DirectoryCleaner.java b/micro-s3/src/main/java/com/oath/micro/server/s3/DirectoryCleaner.java similarity index 98% rename from micro-s3/src/main/java/com/aol/micro/server/s3/DirectoryCleaner.java rename to micro-s3/src/main/java/com/oath/micro/server/s3/DirectoryCleaner.java index 5f079df63..4f0e927ad 100644 --- a/micro-s3/src/main/java/com/aol/micro/server/s3/DirectoryCleaner.java +++ b/micro-s3/src/main/java/com/oath/micro/server/s3/DirectoryCleaner.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.s3; +package com.oath.micro.server.s3; import java.io.File; import java.io.IOException; diff --git a/micro-s3/src/main/java/com/aol/micro/server/s3/S3Configuration.java b/micro-s3/src/main/java/com/oath/micro/server/s3/S3Configuration.java similarity index 98% rename from micro-s3/src/main/java/com/aol/micro/server/s3/S3Configuration.java rename to micro-s3/src/main/java/com/oath/micro/server/s3/S3Configuration.java index 076830cce..4b1beac23 100644 --- a/micro-s3/src/main/java/com/aol/micro/server/s3/S3Configuration.java +++ b/micro-s3/src/main/java/com/oath/micro/server/s3/S3Configuration.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.s3; +package com.oath.micro.server.s3; import lombok.Getter; import org.springframework.beans.factory.annotation.Autowired; diff --git a/micro-s3/src/main/java/com/aol/micro/server/s3/data/ReadUtils.java b/micro-s3/src/main/java/com/oath/micro/server/s3/data/ReadUtils.java similarity index 98% rename from micro-s3/src/main/java/com/aol/micro/server/s3/data/ReadUtils.java rename to micro-s3/src/main/java/com/oath/micro/server/s3/data/ReadUtils.java index c06a250f7..89692f896 100644 --- a/micro-s3/src/main/java/com/aol/micro/server/s3/data/ReadUtils.java +++ b/micro-s3/src/main/java/com/oath/micro/server/s3/data/ReadUtils.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.s3.data; +package com.oath.micro.server.s3.data; import java.io.ByteArrayInputStream; import java.io.File; diff --git a/micro-s3/src/main/java/com/aol/micro/server/s3/data/S3Deleter.java b/micro-s3/src/main/java/com/oath/micro/server/s3/data/S3Deleter.java similarity index 88% rename from micro-s3/src/main/java/com/aol/micro/server/s3/data/S3Deleter.java rename to micro-s3/src/main/java/com/oath/micro/server/s3/data/S3Deleter.java index ea3190879..e63557d41 100644 --- a/micro-s3/src/main/java/com/aol/micro/server/s3/data/S3Deleter.java +++ b/micro-s3/src/main/java/com/oath/micro/server/s3/data/S3Deleter.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.s3.data; +package com.oath.micro.server.s3.data; import com.amazonaws.services.s3.AmazonS3Client; diff --git a/micro-s3/src/main/java/com/aol/micro/server/s3/data/S3DistributedMapClient.java b/micro-s3/src/main/java/com/oath/micro/server/s3/data/S3DistributedMapClient.java similarity index 91% rename from micro-s3/src/main/java/com/aol/micro/server/s3/data/S3DistributedMapClient.java rename to micro-s3/src/main/java/com/oath/micro/server/s3/data/S3DistributedMapClient.java index 92dd6e62a..272371c32 100644 --- a/micro-s3/src/main/java/com/aol/micro/server/s3/data/S3DistributedMapClient.java +++ b/micro-s3/src/main/java/com/oath/micro/server/s3/data/S3DistributedMapClient.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.s3.data; +package com.oath.micro.server.s3.data; import java.util.Optional; @@ -6,7 +6,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; -import com.aol.micro.server.distributed.DistributedMap; +import com.oath.micro.server.distributed.DistributedMap; import lombok.AllArgsConstructor; diff --git a/micro-s3/src/main/java/com/aol/micro/server/s3/data/S3ObjectWriter.java b/micro-s3/src/main/java/com/oath/micro/server/s3/data/S3ObjectWriter.java similarity index 97% rename from micro-s3/src/main/java/com/aol/micro/server/s3/data/S3ObjectWriter.java rename to micro-s3/src/main/java/com/oath/micro/server/s3/data/S3ObjectWriter.java index dd86a7f29..ddfe6058a 100644 --- a/micro-s3/src/main/java/com/aol/micro/server/s3/data/S3ObjectWriter.java +++ b/micro-s3/src/main/java/com/oath/micro/server/s3/data/S3ObjectWriter.java @@ -1,10 +1,8 @@ -package com.aol.micro.server.s3.data; +package com.oath.micro.server.s3.data; import java.io.ByteArrayInputStream; import java.io.File; -import java.io.FileNotFoundException; import java.io.FileOutputStream; -import java.io.IOException; import java.io.InputStream; import java.io.ObjectOutputStream; import java.util.Random; diff --git a/micro-s3/src/main/java/com/aol/micro/server/s3/data/S3Reader.java b/micro-s3/src/main/java/com/oath/micro/server/s3/data/S3Reader.java similarity index 97% rename from micro-s3/src/main/java/com/aol/micro/server/s3/data/S3Reader.java rename to micro-s3/src/main/java/com/oath/micro/server/s3/data/S3Reader.java index 0410b802f..b82e9d7e1 100644 --- a/micro-s3/src/main/java/com/aol/micro/server/s3/data/S3Reader.java +++ b/micro-s3/src/main/java/com/oath/micro/server/s3/data/S3Reader.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.s3.data; +package com.oath.micro.server.s3.data; import java.io.BufferedReader; import java.io.InputStreamReader; diff --git a/micro-s3/src/main/java/com/aol/micro/server/s3/data/S3StringWriter.java b/micro-s3/src/main/java/com/oath/micro/server/s3/data/S3StringWriter.java similarity index 95% rename from micro-s3/src/main/java/com/aol/micro/server/s3/data/S3StringWriter.java rename to micro-s3/src/main/java/com/oath/micro/server/s3/data/S3StringWriter.java index fbd0421bc..01df0e581 100644 --- a/micro-s3/src/main/java/com/aol/micro/server/s3/data/S3StringWriter.java +++ b/micro-s3/src/main/java/com/oath/micro/server/s3/data/S3StringWriter.java @@ -1,8 +1,6 @@ -package com.aol.micro.server.s3.data; +package com.oath.micro.server.s3.data; import java.io.ByteArrayInputStream; -import java.io.File; -import java.util.Random; import java.util.concurrent.ExecutorService; import com.amazonaws.services.s3.AmazonS3Client; @@ -11,7 +9,6 @@ import cyclops.async.Future; import cyclops.control.Try; -import cyclops.matching.Api; import lombok.AllArgsConstructor; @AllArgsConstructor diff --git a/micro-s3/src/main/java/com/aol/micro/server/s3/data/S3Utils.java b/micro-s3/src/main/java/com/oath/micro/server/s3/data/S3Utils.java similarity index 99% rename from micro-s3/src/main/java/com/aol/micro/server/s3/data/S3Utils.java rename to micro-s3/src/main/java/com/oath/micro/server/s3/data/S3Utils.java index 476e2fb4d..c1efddb3f 100644 --- a/micro-s3/src/main/java/com/aol/micro/server/s3/data/S3Utils.java +++ b/micro-s3/src/main/java/com/oath/micro/server/s3/data/S3Utils.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.s3.data; +package com.oath.micro.server.s3.data; import java.io.File; import java.io.IOException; diff --git a/micro-s3/src/main/java/com/aol/micro/server/s3/manifest/comparator/S3ManifestComparator.java b/micro-s3/src/main/java/com/oath/micro/server/s3/manifest/comparator/S3ManifestComparator.java similarity index 95% rename from micro-s3/src/main/java/com/aol/micro/server/s3/manifest/comparator/S3ManifestComparator.java rename to micro-s3/src/main/java/com/oath/micro/server/s3/manifest/comparator/S3ManifestComparator.java index 0d2a89392..6789e53da 100644 --- a/micro-s3/src/main/java/com/aol/micro/server/s3/manifest/comparator/S3ManifestComparator.java +++ b/micro-s3/src/main/java/com/oath/micro/server/s3/manifest/comparator/S3ManifestComparator.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.s3.manifest.comparator; +package com.oath.micro.server.s3.manifest.comparator; import java.util.Date; @@ -11,15 +11,15 @@ import org.slf4j.LoggerFactory; -import com.aol.micro.server.manifest.Data; -import com.aol.micro.server.manifest.ManifestComparator; -import com.aol.micro.server.manifest.ManifestComparatorKeyNotFoundException; -import com.aol.micro.server.manifest.VersionedKey; -import com.aol.micro.server.rest.jackson.JacksonUtil; -import com.aol.micro.server.s3.data.S3Deleter; -import com.aol.micro.server.s3.data.S3ObjectWriter; -import com.aol.micro.server.s3.data.S3Reader; -import com.aol.micro.server.s3.data.S3StringWriter; +import com.oath.micro.server.manifest.Data; +import com.oath.micro.server.manifest.ManifestComparator; +import com.oath.micro.server.manifest.ManifestComparatorKeyNotFoundException; +import com.oath.micro.server.manifest.VersionedKey; +import com.oath.micro.server.rest.jackson.JacksonUtil; +import com.oath.micro.server.s3.data.S3Deleter; +import com.oath.micro.server.s3.data.S3ObjectWriter; +import com.oath.micro.server.s3.data.S3Reader; +import com.oath.micro.server.s3.data.S3StringWriter; import lombok.AccessLevel; import lombok.AllArgsConstructor; diff --git a/micro-s3/src/main/java/com/aol/micro/server/s3/plugin/S3ClientProvider.java b/micro-s3/src/main/java/com/oath/micro/server/s3/plugin/S3ClientProvider.java similarity index 93% rename from micro-s3/src/main/java/com/aol/micro/server/s3/plugin/S3ClientProvider.java rename to micro-s3/src/main/java/com/oath/micro/server/s3/plugin/S3ClientProvider.java index 20cecf96c..851101871 100644 --- a/micro-s3/src/main/java/com/aol/micro/server/s3/plugin/S3ClientProvider.java +++ b/micro-s3/src/main/java/com/oath/micro/server/s3/plugin/S3ClientProvider.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.s3.plugin; +package com.oath.micro.server.s3.plugin; import com.amazonaws.ClientConfiguration; import com.amazonaws.auth.DefaultAWSCredentialsProviderChain; @@ -13,10 +13,10 @@ import com.amazonaws.regions.Region; import com.amazonaws.regions.Regions; import com.amazonaws.services.s3.AmazonS3Client; -import com.aol.micro.server.s3.S3Configuration; +import com.oath.micro.server.s3.S3Configuration; @Configuration -@ComponentScan(basePackages = {"com.aol.micro.server.s3"}) +@ComponentScan(basePackages = {"com.oath.micro.server.s3"}) public class S3ClientProvider { @Autowired diff --git a/micro-s3/src/main/java/com/aol/micro/server/s3/plugin/S3ManifestComparatorProvider.java b/micro-s3/src/main/java/com/oath/micro/server/s3/plugin/S3ManifestComparatorProvider.java similarity index 84% rename from micro-s3/src/main/java/com/aol/micro/server/s3/plugin/S3ManifestComparatorProvider.java rename to micro-s3/src/main/java/com/oath/micro/server/s3/plugin/S3ManifestComparatorProvider.java index b88e8954a..4dcc03300 100644 --- a/micro-s3/src/main/java/com/aol/micro/server/s3/plugin/S3ManifestComparatorProvider.java +++ b/micro-s3/src/main/java/com/oath/micro/server/s3/plugin/S3ManifestComparatorProvider.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.s3.plugin; +package com.oath.micro.server.s3.plugin; import java.io.IOException; import java.net.URISyntaxException; @@ -8,8 +8,8 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import com.aol.micro.server.s3.data.S3Utils; -import com.aol.micro.server.s3.manifest.comparator.S3ManifestComparator; +import com.oath.micro.server.s3.data.S3Utils; +import com.oath.micro.server.s3.manifest.comparator.S3ManifestComparator; @Configuration public class S3ManifestComparatorProvider { diff --git a/micro-s3/src/main/java/com/oath/micro/server/s3/plugin/S3Plugin.java b/micro-s3/src/main/java/com/oath/micro/server/s3/plugin/S3Plugin.java new file mode 100644 index 000000000..c541cc1f6 --- /dev/null +++ b/micro-s3/src/main/java/com/oath/micro/server/s3/plugin/S3Plugin.java @@ -0,0 +1,21 @@ +package com.oath.micro.server.s3.plugin; + + +import com.oath.micro.server.Plugin; +import com.oath.micro.server.s3.DirectoryCleaner; +import com.oath.micro.server.s3.S3Configuration; +import com.oath.micro.server.s3.data.S3DistributedMapClient; +import com.oath.micro.server.s3.data.S3Utils; +import cyclops.collections.mutable.SetX; + +import java.util.Set; + +public class S3Plugin implements Plugin { + + @Override + public Set springClasses() { + return SetX.of(S3ManifestComparatorProvider.class, S3DistributedMapClient.class, S3Configuration.class, + S3ClientProvider.class, S3Utils.class, S3TransferManagerProvider.class, DirectoryCleaner.class); + } + +} diff --git a/micro-s3/src/main/java/com/aol/micro/server/s3/plugin/S3TransferManagerProvider.java b/micro-s3/src/main/java/com/oath/micro/server/s3/plugin/S3TransferManagerProvider.java similarity index 93% rename from micro-s3/src/main/java/com/aol/micro/server/s3/plugin/S3TransferManagerProvider.java rename to micro-s3/src/main/java/com/oath/micro/server/s3/plugin/S3TransferManagerProvider.java index c17226ffd..9e7cf936a 100644 --- a/micro-s3/src/main/java/com/aol/micro/server/s3/plugin/S3TransferManagerProvider.java +++ b/micro-s3/src/main/java/com/oath/micro/server/s3/plugin/S3TransferManagerProvider.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.s3.plugin; +package com.oath.micro.server.s3.plugin; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -10,7 +10,7 @@ import com.amazonaws.services.s3.AmazonS3Client; import com.amazonaws.services.s3.transfer.TransferManager; -import com.aol.micro.server.s3.S3Configuration; +import com.oath.micro.server.s3.S3Configuration; @Configuration public class S3TransferManagerProvider { diff --git a/micro-s3/src/main/resources/META-INF/services/com.aol.micro.server.Plugin b/micro-s3/src/main/resources/META-INF/services/com.aol.micro.server.Plugin deleted file mode 100644 index 80708d4d8..000000000 --- a/micro-s3/src/main/resources/META-INF/services/com.aol.micro.server.Plugin +++ /dev/null @@ -1 +0,0 @@ -com.aol.micro.server.s3.plugin.S3Plugin \ No newline at end of file diff --git a/micro-s3/src/main/resources/META-INF/services/com.oath.micro.server.Plugin b/micro-s3/src/main/resources/META-INF/services/com.oath.micro.server.Plugin new file mode 100644 index 000000000..2f2ec9682 --- /dev/null +++ b/micro-s3/src/main/resources/META-INF/services/com.oath.micro.server.Plugin @@ -0,0 +1 @@ +com.oath.micro.server.s3.plugin.S3Plugin \ No newline at end of file diff --git a/micro-s3/src/test/java/app/s3/distributed/map/com/aol/micro/server/S3Resource.java b/micro-s3/src/test/java/app/s3/distributed/map/com/aol/micro/server/S3Resource.java deleted file mode 100644 index d3fe8dacb..000000000 --- a/micro-s3/src/test/java/app/s3/distributed/map/com/aol/micro/server/S3Resource.java +++ /dev/null @@ -1,35 +0,0 @@ -package app.s3.distributed.map.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; - -import org.springframework.beans.factory.annotation.Autowired; - -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.distributed.DistributedMap; - -@Path("/s3") -@Rest -public class S3Resource { - - private final DistributedMap client; - - @Autowired - public S3Resource(DistributedMap client) { - this.client = client; - } - - @GET - @Path("/get") - public String bucket() { - return client.get("hello") - .toString(); - } - - @GET - @Path("/put") - public String put() { - client.put("hello", "world"); - return "added"; - } -} diff --git a/micro-s3/src/test/java/app/s3/distributed/map/com/aol/micro/server/S3RunnerTest.java b/micro-s3/src/test/java/app/s3/distributed/map/com/aol/micro/server/S3RunnerTest.java deleted file mode 100644 index 6750b6c20..000000000 --- a/micro-s3/src/test/java/app/s3/distributed/map/com/aol/micro/server/S3RunnerTest.java +++ /dev/null @@ -1,46 +0,0 @@ -package app.s3.distributed.map.com.aol.micro.server; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.testing.RestAgent; - -@Ignore -public class S3RunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - - @Before - public void startServer() { - - server = new MicroserverApp( - () -> "simple-app"); - - server.start(); - - } - - @After - public void stopServer() { - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException { - rest.get("http://localhost:8080/simple-app/s3/put"); - System.out.println("hello"); - assertThat(rest.get("http://localhost:8080/simple-app/s3/get"), containsString("world")); - - } - -} diff --git a/micro-s3/src/test/java/app/s3/distributed/map/com/oath/micro/server/S3Resource.java b/micro-s3/src/test/java/app/s3/distributed/map/com/oath/micro/server/S3Resource.java new file mode 100644 index 000000000..50cad3450 --- /dev/null +++ b/micro-s3/src/test/java/app/s3/distributed/map/com/oath/micro/server/S3Resource.java @@ -0,0 +1,35 @@ +package app.s3.distributed.map.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +import org.springframework.beans.factory.annotation.Autowired; + +import com.oath.micro.server.auto.discovery.Rest; +import com.oath.micro.server.distributed.DistributedMap; + +@Path("/s3") +@Rest +public class S3Resource { + + private final DistributedMap client; + + @Autowired + public S3Resource(DistributedMap client) { + this.client = client; + } + + @GET + @Path("/get") + public String bucket() { + return client.get("hello") + .toString(); + } + + @GET + @Path("/put") + public String put() { + client.put("hello", "world"); + return "added"; + } +} diff --git a/micro-s3/src/test/java/app/s3/distributed/map/com/oath/micro/server/S3RunnerTest.java b/micro-s3/src/test/java/app/s3/distributed/map/com/oath/micro/server/S3RunnerTest.java new file mode 100644 index 000000000..65facba5d --- /dev/null +++ b/micro-s3/src/test/java/app/s3/distributed/map/com/oath/micro/server/S3RunnerTest.java @@ -0,0 +1,46 @@ +package app.s3.distributed.map.com.oath.micro.server; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.testing.RestAgent; + +@Ignore +public class S3RunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + + @Before + public void startServer() { + + server = new MicroserverApp( + () -> "simple-app"); + + server.start(); + + } + + @After + public void stopServer() { + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException { + rest.get("http://localhost:8080/simple-app/s3/put"); + System.out.println("hello"); + assertThat(rest.get("http://localhost:8080/simple-app/s3/get"), containsString("world")); + + } + +} diff --git a/micro-s3/src/test/java/app/s3/manifest/comparator/com/aol/micro/server/second/ManifestComparatorResource.java b/micro-s3/src/test/java/app/s3/manifest/comparator/com/aol/micro/server/second/ManifestComparatorResource.java deleted file mode 100644 index 5984a7db7..000000000 --- a/micro-s3/src/test/java/app/s3/manifest/comparator/com/aol/micro/server/second/ManifestComparatorResource.java +++ /dev/null @@ -1,45 +0,0 @@ -package app.s3.manifest.comparator.com.aol.micro.server.second; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; - -import org.springframework.beans.factory.annotation.Autowired; - -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.manifest.ManifestComparator; - -@Path("/comparator") -@Rest -public class ManifestComparatorResource { - - private volatile int count = 1; - private final ManifestComparator comparator; - - @Autowired - public ManifestComparatorResource(ManifestComparator comparator) { - this.comparator = comparator. withKey("test-key5"); - } - - @GET - @Path("/increment") - public String bucket() { - comparator.saveAndIncrement("hello" + (count++)); - return "increment"; - } - - @GET - @Path("/get") - public String get() { - comparator.load(); - return comparator.getData() - .toString(); - - } - - @GET - @Path("/check") - public String check() { - return "" + !comparator.isOutOfDate(); - - } -} diff --git a/micro-s3/src/test/java/app/s3/manifest/comparator/com/aol/micro/server/second/ManifestComparatorRunnerTest.java b/micro-s3/src/test/java/app/s3/manifest/comparator/com/aol/micro/server/second/ManifestComparatorRunnerTest.java deleted file mode 100644 index 5d1517fc1..000000000 --- a/micro-s3/src/test/java/app/s3/manifest/comparator/com/aol/micro/server/second/ManifestComparatorRunnerTest.java +++ /dev/null @@ -1,54 +0,0 @@ -package app.s3.manifest.comparator.com.aol.micro.server.second; - -import static org.hamcrest.CoreMatchers.equalTo; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.testing.RestAgent; - -public class ManifestComparatorRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - - @Before - public void startServer() { - - server = new MicroserverApp( - () -> "simple-app"); - - server.start(); - - } - - @After - public void stopServer() { - server.stop(); - } - - @Test - @Ignore - public void runAppAndBasicTest() throws InterruptedException, ExecutionException { - rest.get("http://localhost:8080/simple-app/comparator/increment"); - - assertThat(rest.get("http://localhost:8080/simple-app/comparator/check"), equalTo("true")); - assertThat(rest.get("http://localhost:8080/simple-app/comparator/get"), equalTo("hello1")); - rest.get("http://localhost:8080/simple-app/comparator/increment"); - assertThat(rest.get("http://localhost:8080/simple-app/comparator/get"), equalTo("hello2")); - - rest.get("http://localhost:8080/simple-app/comparator2/increment"); - - assertThat(rest.get("http://localhost:8080/simple-app/comparator/check"), equalTo("false")); - assertThat(rest.get("http://localhost:8080/simple-app/comparator/get"), equalTo("hellob")); - - } - -} diff --git a/micro-s3/src/test/java/app/s3/manifest/comparator/com/aol/micro/server/second/SecondComparatorResource.java b/micro-s3/src/test/java/app/s3/manifest/comparator/com/aol/micro/server/second/SecondComparatorResource.java deleted file mode 100644 index 3f76feccd..000000000 --- a/micro-s3/src/test/java/app/s3/manifest/comparator/com/aol/micro/server/second/SecondComparatorResource.java +++ /dev/null @@ -1,44 +0,0 @@ -package app.s3.manifest.comparator.com.aol.micro.server.second; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; - -import org.springframework.beans.factory.annotation.Autowired; - -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.manifest.ManifestComparator; - -@Path("/comparator2") -@Rest -public class SecondComparatorResource { - - private final ManifestComparator comparator; - - @Autowired - public SecondComparatorResource(ManifestComparator comparator) { - this.comparator = comparator.withKey("test-key5"); - } - - @GET - @Path("/increment") - public String bucket() { - comparator.saveAndIncrement("hellob"); - return "increment"; - } - - @GET - @Path("/get") - public String get() { - comparator.load(); - return comparator.getData() - .toString(); - - } - - @GET - @Path("/check") - public String check() { - return "" + !comparator.isOutOfDate(); - - } -} \ No newline at end of file diff --git a/micro-s3/src/test/java/app/s3/manifest/comparator/com/oath/micro/server/second/ManifestComparatorResource.java b/micro-s3/src/test/java/app/s3/manifest/comparator/com/oath/micro/server/second/ManifestComparatorResource.java new file mode 100644 index 000000000..78d4a44b1 --- /dev/null +++ b/micro-s3/src/test/java/app/s3/manifest/comparator/com/oath/micro/server/second/ManifestComparatorResource.java @@ -0,0 +1,45 @@ +package app.s3.manifest.comparator.com.oath.micro.server.second; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +import org.springframework.beans.factory.annotation.Autowired; + +import com.oath.micro.server.auto.discovery.Rest; +import com.oath.micro.server.manifest.ManifestComparator; + +@Path("/comparator") +@Rest +public class ManifestComparatorResource { + + private volatile int count = 1; + private final ManifestComparator comparator; + + @Autowired + public ManifestComparatorResource(ManifestComparator comparator) { + this.comparator = comparator. withKey("test-key5"); + } + + @GET + @Path("/increment") + public String bucket() { + comparator.saveAndIncrement("hello" + (count++)); + return "increment"; + } + + @GET + @Path("/get") + public String get() { + comparator.load(); + return comparator.getData() + .toString(); + + } + + @GET + @Path("/check") + public String check() { + return "" + !comparator.isOutOfDate(); + + } +} diff --git a/micro-s3/src/test/java/app/s3/manifest/comparator/com/oath/micro/server/second/ManifestComparatorRunnerTest.java b/micro-s3/src/test/java/app/s3/manifest/comparator/com/oath/micro/server/second/ManifestComparatorRunnerTest.java new file mode 100644 index 000000000..8f43dbb5c --- /dev/null +++ b/micro-s3/src/test/java/app/s3/manifest/comparator/com/oath/micro/server/second/ManifestComparatorRunnerTest.java @@ -0,0 +1,54 @@ +package app.s3.manifest.comparator.com.oath.micro.server.second; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.testing.RestAgent; + +public class ManifestComparatorRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + + @Before + public void startServer() { + + server = new MicroserverApp( + () -> "simple-app"); + + server.start(); + + } + + @After + public void stopServer() { + server.stop(); + } + + @Test + @Ignore + public void runAppAndBasicTest() throws InterruptedException, ExecutionException { + rest.get("http://localhost:8080/simple-app/comparator/increment"); + + assertThat(rest.get("http://localhost:8080/simple-app/comparator/check"), equalTo("true")); + assertThat(rest.get("http://localhost:8080/simple-app/comparator/get"), equalTo("hello1")); + rest.get("http://localhost:8080/simple-app/comparator/increment"); + assertThat(rest.get("http://localhost:8080/simple-app/comparator/get"), equalTo("hello2")); + + rest.get("http://localhost:8080/simple-app/comparator2/increment"); + + assertThat(rest.get("http://localhost:8080/simple-app/comparator/check"), equalTo("false")); + assertThat(rest.get("http://localhost:8080/simple-app/comparator/get"), equalTo("hellob")); + + } + +} diff --git a/micro-s3/src/test/java/app/s3/manifest/comparator/com/oath/micro/server/second/SecondComparatorResource.java b/micro-s3/src/test/java/app/s3/manifest/comparator/com/oath/micro/server/second/SecondComparatorResource.java new file mode 100644 index 000000000..ef75b6f2c --- /dev/null +++ b/micro-s3/src/test/java/app/s3/manifest/comparator/com/oath/micro/server/second/SecondComparatorResource.java @@ -0,0 +1,44 @@ +package app.s3.manifest.comparator.com.oath.micro.server.second; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +import org.springframework.beans.factory.annotation.Autowired; + +import com.oath.micro.server.auto.discovery.Rest; +import com.oath.micro.server.manifest.ManifestComparator; + +@Path("/comparator2") +@Rest +public class SecondComparatorResource { + + private final ManifestComparator comparator; + + @Autowired + public SecondComparatorResource(ManifestComparator comparator) { + this.comparator = comparator.withKey("test-key5"); + } + + @GET + @Path("/increment") + public String bucket() { + comparator.saveAndIncrement("hellob"); + return "increment"; + } + + @GET + @Path("/get") + public String get() { + comparator.load(); + return comparator.getData() + .toString(); + + } + + @GET + @Path("/check") + public String check() { + return "" + !comparator.isOutOfDate(); + + } +} \ No newline at end of file diff --git a/micro-s3/src/test/java/app/s3/rw/map/com/aol/micro/server/S3Resource.java b/micro-s3/src/test/java/app/s3/rw/map/com/aol/micro/server/S3Resource.java deleted file mode 100644 index 7cf557790..000000000 --- a/micro-s3/src/test/java/app/s3/rw/map/com/aol/micro/server/S3Resource.java +++ /dev/null @@ -1,45 +0,0 @@ -package app.s3.rw.map.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; - -import com.aol.micro.server.s3.data.S3ObjectWriter; -import com.aol.micro.server.s3.data.S3Reader; -import com.aol.micro.server.s3.data.S3Utils; -import cyclops.control.Try; -import org.springframework.beans.factory.annotation.Autowired; - -import com.amazonaws.services.s3.transfer.Upload; - -import com.aol.micro.server.auto.discovery.Rest; - - -@Path("/s3") -@Rest -public class S3Resource { - - private final S3Reader client; - private final S3ObjectWriter writer; - - @Autowired - public S3Resource(S3Utils utils) { - this.client = utils.reader("aolp-lana-dev-test-partition-us-east-1"); - this.writer = utils.writer("aolp-lana-dev-test-partition-us-east-1"); - } - - @GET - @Path("/get") - public String bucket() { - return client.getAsString("hello") - .orElse(""); - } - - @GET - @Path("/put") - public String put() { - Try operation = writer.put("hello", "world"); - if(operation.isSuccess()) - return "added"; - return operation.failureGet().orElse(null).getMessage(); - } -} diff --git a/micro-s3/src/test/java/app/s3/rw/map/com/aol/micro/server/S3RunnerTest.java b/micro-s3/src/test/java/app/s3/rw/map/com/aol/micro/server/S3RunnerTest.java deleted file mode 100644 index a67568aa0..000000000 --- a/micro-s3/src/test/java/app/s3/rw/map/com/aol/micro/server/S3RunnerTest.java +++ /dev/null @@ -1,45 +0,0 @@ -package app.s3.rw.map.com.aol.micro.server; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.testing.RestAgent; - -public class S3RunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - - @Before - public void startServer() { - - server = new MicroserverApp( - () -> "simple-app"); - - server.start(); - - } - - @After - public void stopServer() { - server.stop(); - } - - @Test - @Ignore - public void runAppAndBasicTest() throws InterruptedException, ExecutionException { - rest.get("http://localhost:8080/simple-app/s3/put"); - assertThat(rest.get("http://localhost:8080/simple-app/s3/get"), containsString("world")); - - } - -} diff --git a/micro-s3/src/test/java/app/s3/rw/map/com/oath/micro/server/S3Resource.java b/micro-s3/src/test/java/app/s3/rw/map/com/oath/micro/server/S3Resource.java new file mode 100644 index 000000000..7ee2a569f --- /dev/null +++ b/micro-s3/src/test/java/app/s3/rw/map/com/oath/micro/server/S3Resource.java @@ -0,0 +1,45 @@ +package app.s3.rw.map.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +import com.oath.micro.server.s3.data.S3ObjectWriter; +import com.oath.micro.server.s3.data.S3Reader; +import com.oath.micro.server.s3.data.S3Utils; +import cyclops.control.Try; +import org.springframework.beans.factory.annotation.Autowired; + +import com.amazonaws.services.s3.transfer.Upload; + +import com.oath.micro.server.auto.discovery.Rest; + + +@Path("/s3") +@Rest +public class S3Resource { + + private final S3Reader client; + private final S3ObjectWriter writer; + + @Autowired + public S3Resource(S3Utils utils) { + this.client = utils.reader("aolp-lana-dev-test-partition-us-east-1"); + this.writer = utils.writer("aolp-lana-dev-test-partition-us-east-1"); + } + + @GET + @Path("/get") + public String bucket() { + return client.getAsString("hello") + .orElse(""); + } + + @GET + @Path("/put") + public String put() { + Try operation = writer.put("hello", "world"); + if(operation.isSuccess()) + return "added"; + return operation.failureGet().orElse(null).getMessage(); + } +} diff --git a/micro-s3/src/test/java/app/s3/rw/map/com/oath/micro/server/S3RunnerTest.java b/micro-s3/src/test/java/app/s3/rw/map/com/oath/micro/server/S3RunnerTest.java new file mode 100644 index 000000000..4ddeecb26 --- /dev/null +++ b/micro-s3/src/test/java/app/s3/rw/map/com/oath/micro/server/S3RunnerTest.java @@ -0,0 +1,45 @@ +package app.s3.rw.map.com.oath.micro.server; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.testing.RestAgent; + +public class S3RunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + + @Before + public void startServer() { + + server = new MicroserverApp( + () -> "simple-app"); + + server.start(); + + } + + @After + public void stopServer() { + server.stop(); + } + + @Test + @Ignore + public void runAppAndBasicTest() throws InterruptedException, ExecutionException { + rest.get("http://localhost:8080/simple-app/s3/put"); + assertThat(rest.get("http://localhost:8080/simple-app/s3/get"), containsString("world")); + + } + +} diff --git a/micro-s3/src/test/java/com/aol/micro/server/s3/S3RunnerTest.java b/micro-s3/src/test/java/com/aol/micro/server/s3/S3RunnerTest.java deleted file mode 100644 index 7b0670856..000000000 --- a/micro-s3/src/test/java/com/aol/micro/server/s3/S3RunnerTest.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.aol.micro.server.s3; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.amazonaws.services.s3.AmazonS3Client; -import com.amazonaws.services.s3.transfer.TransferManager; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.s3.data.S3Utils; - -@Microserver(properties = { "s3.accessKey", "", "s3.secretKey", "" }) -public class S3RunnerTest { - - MicroserverApp server; - - @Before - public void startServer() { - - server = new MicroserverApp( - () -> "s3"); - server.start(); - - } - - @After - public void stopServer() { - server.stop(); - } - - @Test - public void runAppAndBasicTest() { - - AmazonS3Client s3client = server.getSpringContext() - .getBean(AmazonS3Client.class); - assertThat(s3client != null, is(true)); - - S3Configuration s3Configuration = server.getSpringContext() - .getBean(S3Configuration.class); - assertThat(s3Configuration.getAccessKey(), is("")); - assertThat(s3Configuration.getSecretKey(), is("")); - assertThat(s3Configuration.getSessionToken() == null, is(true)); - assertThat(s3Configuration.getRegion() == null, is(true)); - assertThat(s3Configuration.getUploadThreads(), is(5)); - assertThat(s3Configuration.getUploadThreadNamePrefix(), is("s3-transfer-manager-worker-")); - - S3Utils s3Utils = server.getSpringContext() - .getBean(S3Utils.class); - assertThat(s3Utils != null, is(true)); - - TransferManager tm = server.getSpringContext() - .getBean(TransferManager.class); - assertThat(tm != null, is(true)); - - } - -} diff --git a/micro-s3/src/test/java/com/aol/micro/server/testing/RestAgent.java b/micro-s3/src/test/java/com/aol/micro/server/testing/RestAgent.java deleted file mode 100644 index ce204f810..000000000 --- a/micro-s3/src/test/java/com/aol/micro/server/testing/RestAgent.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.aol.micro.server.testing; - -import java.util.List; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.Invocation.Builder; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; - -import com.aol.micro.server.rest.jackson.JacksonUtil; - -public class RestAgent { - - - public String getJson(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.get(String.class); - - } - - public String get(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.TEXT_PLAIN); - - return request.get(String.class); - - } - - public T post(String url, Object payload,Class type) { - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); - } - - -} diff --git a/micro-s3/src/test/java/com/aol/micro/server/s3/DirectoryCleanerTest.java b/micro-s3/src/test/java/com/oath/micro/server/s3/DirectoryCleanerTest.java similarity index 94% rename from micro-s3/src/test/java/com/aol/micro/server/s3/DirectoryCleanerTest.java rename to micro-s3/src/test/java/com/oath/micro/server/s3/DirectoryCleanerTest.java index 60a0a1eb7..8dabccb3b 100644 --- a/micro-s3/src/test/java/com/aol/micro/server/s3/DirectoryCleanerTest.java +++ b/micro-s3/src/test/java/com/oath/micro/server/s3/DirectoryCleanerTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.s3; +package com.oath.micro.server.s3; import java.io.IOException; import java.nio.file.Files; diff --git a/micro-s3/src/test/java/com/aol/micro/server/s3/ReadUtilsTest.java b/micro-s3/src/test/java/com/oath/micro/server/s3/ReadUtilsTest.java similarity index 95% rename from micro-s3/src/test/java/com/aol/micro/server/s3/ReadUtilsTest.java rename to micro-s3/src/test/java/com/oath/micro/server/s3/ReadUtilsTest.java index fa8be0603..9e3a046da 100644 --- a/micro-s3/src/test/java/com/aol/micro/server/s3/ReadUtilsTest.java +++ b/micro-s3/src/test/java/com/oath/micro/server/s3/ReadUtilsTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.s3; +package com.oath.micro.server.s3; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyString; @@ -17,7 +17,7 @@ import com.amazonaws.AmazonServiceException; import com.amazonaws.services.s3.transfer.Download; import com.amazonaws.services.s3.transfer.TransferManager; -import com.aol.micro.server.s3.data.ReadUtils; +import com.oath.micro.server.s3.data.ReadUtils; public class ReadUtilsTest { diff --git a/micro-s3/src/test/java/com/oath/micro/server/s3/S3RunnerTest.java b/micro-s3/src/test/java/com/oath/micro/server/s3/S3RunnerTest.java new file mode 100644 index 000000000..404edb4a6 --- /dev/null +++ b/micro-s3/src/test/java/com/oath/micro/server/s3/S3RunnerTest.java @@ -0,0 +1,61 @@ +package com.oath.micro.server.s3; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.amazonaws.services.s3.AmazonS3Client; +import com.amazonaws.services.s3.transfer.TransferManager; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.s3.data.S3Utils; + +@Microserver(properties = { "s3.accessKey", "", "s3.secretKey", "" }) +public class S3RunnerTest { + + MicroserverApp server; + + @Before + public void startServer() { + + server = new MicroserverApp( + () -> "s3"); + server.start(); + + } + + @After + public void stopServer() { + server.stop(); + } + + @Test + public void runAppAndBasicTest() { + + AmazonS3Client s3client = server.getSpringContext() + .getBean(AmazonS3Client.class); + assertThat(s3client != null, is(true)); + + S3Configuration s3Configuration = server.getSpringContext() + .getBean(S3Configuration.class); + assertThat(s3Configuration.getAccessKey(), is("")); + assertThat(s3Configuration.getSecretKey(), is("")); + assertThat(s3Configuration.getSessionToken() == null, is(true)); + assertThat(s3Configuration.getRegion() == null, is(true)); + assertThat(s3Configuration.getUploadThreads(), is(5)); + assertThat(s3Configuration.getUploadThreadNamePrefix(), is("s3-transfer-manager-worker-")); + + S3Utils s3Utils = server.getSpringContext() + .getBean(S3Utils.class); + assertThat(s3Utils != null, is(true)); + + TransferManager tm = server.getSpringContext() + .getBean(TransferManager.class); + assertThat(tm != null, is(true)); + + } + +} diff --git a/micro-s3/src/test/java/com/aol/micro/server/s3/S3UtilsTest.java b/micro-s3/src/test/java/com/oath/micro/server/s3/S3UtilsTest.java similarity index 91% rename from micro-s3/src/test/java/com/aol/micro/server/s3/S3UtilsTest.java rename to micro-s3/src/test/java/com/oath/micro/server/s3/S3UtilsTest.java index eb1dd7ed2..5bbe2b6e1 100644 --- a/micro-s3/src/test/java/com/aol/micro/server/s3/S3UtilsTest.java +++ b/micro-s3/src/test/java/com/oath/micro/server/s3/S3UtilsTest.java @@ -1,34 +1,25 @@ -package com.aol.micro.server.s3; +package com.oath.micro.server.s3; import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import java.io.File; import java.io.IOException; -import java.nio.file.Files; import java.util.ArrayList; import java.util.List; import java.util.stream.Stream; -import org.junit.Assert; import org.junit.Test; -import com.amazonaws.AmazonClientException; -import com.amazonaws.AmazonServiceException; import com.amazonaws.services.s3.AmazonS3Client; import com.amazonaws.services.s3.model.DeleteObjectsRequest.KeyVersion; import com.amazonaws.services.s3.model.ListObjectsRequest; import com.amazonaws.services.s3.model.ObjectListing; -import com.amazonaws.services.s3.model.S3Object; import com.amazonaws.services.s3.model.S3ObjectSummary; -import com.amazonaws.services.s3.transfer.Download; -import com.amazonaws.services.s3.transfer.TransferManager; -import com.aol.micro.server.s3.data.S3Utils; +import com.oath.micro.server.s3.data.S3Utils; public class S3UtilsTest { diff --git a/micro-s3/src/test/java/com/aol/micro/server/s3/data/S3DownloadSystemTest.java b/micro-s3/src/test/java/com/oath/micro/server/s3/data/S3DownloadSystemTest.java similarity index 97% rename from micro-s3/src/test/java/com/aol/micro/server/s3/data/S3DownloadSystemTest.java rename to micro-s3/src/test/java/com/oath/micro/server/s3/data/S3DownloadSystemTest.java index 16dab1846..83b4de2a0 100644 --- a/micro-s3/src/test/java/com/aol/micro/server/s3/data/S3DownloadSystemTest.java +++ b/micro-s3/src/test/java/com/oath/micro/server/s3/data/S3DownloadSystemTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.s3.data; +package com.oath.micro.server.s3.data; import static org.coursera.metrics.datadog.DatadogReporter.Expansion.COUNT; import static org.coursera.metrics.datadog.DatadogReporter.Expansion.MEAN; @@ -44,7 +44,7 @@ public class S3DownloadSystemTest{ private static File tmpDir; private static Random r; private static MetricRegistry metricsRegistry = SharedMetricRegistries.getOrCreate("default"); - private final Histogram downloadHist = getHistogram("com.aol.micro.server.s3.test.latency.download"); + private final Histogram downloadHist = getHistogram("com.oath.micro.server.s3.test.latency.download"); static { manager = createManager(); diff --git a/micro-s3/src/test/java/com/aol/micro/server/s3/data/S3UploadSystemTest.java b/micro-s3/src/test/java/com/oath/micro/server/s3/data/S3UploadSystemTest.java similarity index 96% rename from micro-s3/src/test/java/com/aol/micro/server/s3/data/S3UploadSystemTest.java rename to micro-s3/src/test/java/com/oath/micro/server/s3/data/S3UploadSystemTest.java index 3b2323072..e4c574bc4 100644 --- a/micro-s3/src/test/java/com/aol/micro/server/s3/data/S3UploadSystemTest.java +++ b/micro-s3/src/test/java/com/oath/micro/server/s3/data/S3UploadSystemTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.s3.data; +package com.oath.micro.server.s3.data; import static org.coursera.metrics.datadog.DatadogReporter.Expansion.*; import static org.junit.Assert.assertTrue; @@ -41,8 +41,8 @@ public class S3UploadSystemTest{ private static File tmpDir; private static Random r; private static MetricRegistry metricsRegistry = SharedMetricRegistries.getOrCreate("default"); - private final Histogram unencryptedHist = getHistogram("com.aol.micro.server.s3.test.latency.unencrypted"); - private final Histogram aes256Hist = getHistogram("com.aol.micro.server.s3.test.latency.aes256"); + private final Histogram unencryptedHist = getHistogram("com.oath.micro.server.s3.test.latency.unencrypted"); + private final Histogram aes256Hist = getHistogram("com.oath.micro.server.s3.test.latency.aes256"); static { nullableFile = createNullableFile(); diff --git a/micro-s3/src/test/java/com/aol/micro/server/s3/manifest/comparator/S3ManifestComparatorTest.java b/micro-s3/src/test/java/com/oath/micro/server/s3/manifest/comparator/S3ManifestComparatorTest.java similarity index 87% rename from micro-s3/src/test/java/com/aol/micro/server/s3/manifest/comparator/S3ManifestComparatorTest.java rename to micro-s3/src/test/java/com/oath/micro/server/s3/manifest/comparator/S3ManifestComparatorTest.java index 1f0748c8e..14f6fc8d1 100644 --- a/micro-s3/src/test/java/com/aol/micro/server/s3/manifest/comparator/S3ManifestComparatorTest.java +++ b/micro-s3/src/test/java/com/oath/micro/server/s3/manifest/comparator/S3ManifestComparatorTest.java @@ -1,12 +1,12 @@ -package com.aol.micro.server.s3.manifest.comparator; +package com.oath.micro.server.s3.manifest.comparator; -import com.aol.micro.server.manifest.Data; -import com.aol.micro.server.manifest.VersionedKey; -import com.aol.micro.server.s3.data.S3Deleter; -import com.aol.micro.server.s3.data.S3ObjectWriter; -import com.aol.micro.server.s3.data.S3Reader; -import com.aol.micro.server.s3.data.S3StringWriter; +import com.oath.micro.server.manifest.Data; +import com.oath.micro.server.manifest.VersionedKey; +import com.oath.micro.server.s3.data.S3Deleter; +import com.oath.micro.server.s3.data.S3ObjectWriter; +import com.oath.micro.server.s3.data.S3Reader; +import com.oath.micro.server.s3.data.S3StringWriter; import cyclops.control.Try; import org.junit.Before; import org.junit.Test; diff --git a/micro-s3/src/test/java/com/aol/micro/server/s3/plugin/S3ClientProviderTest.java b/micro-s3/src/test/java/com/oath/micro/server/s3/plugin/S3ClientProviderTest.java similarity index 98% rename from micro-s3/src/test/java/com/aol/micro/server/s3/plugin/S3ClientProviderTest.java rename to micro-s3/src/test/java/com/oath/micro/server/s3/plugin/S3ClientProviderTest.java index 1548d8e5b..19f22ac2f 100644 --- a/micro-s3/src/test/java/com/aol/micro/server/s3/plugin/S3ClientProviderTest.java +++ b/micro-s3/src/test/java/com/oath/micro/server/s3/plugin/S3ClientProviderTest.java @@ -1,9 +1,9 @@ -package com.aol.micro.server.s3.plugin; +package com.oath.micro.server.s3.plugin; import com.amazonaws.auth.AWSCredentials; import com.amazonaws.auth.BasicSessionCredentials; import com.amazonaws.services.s3.AmazonS3Client; -import com.aol.micro.server.s3.S3Configuration; +import com.oath.micro.server.s3.S3Configuration; import lombok.SneakyThrows; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/micro-s3/src/test/java/com/oath/micro/server/testing/RestAgent.java b/micro-s3/src/test/java/com/oath/micro/server/testing/RestAgent.java new file mode 100644 index 000000000..b2b86303e --- /dev/null +++ b/micro-s3/src/test/java/com/oath/micro/server/testing/RestAgent.java @@ -0,0 +1,53 @@ +package com.oath.micro.server.testing; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.Invocation.Builder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; + +import com.oath.micro.server.rest.jackson.JacksonUtil; + +public class RestAgent { + + + public String getJson(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.get(String.class); + + } + + public String get(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.TEXT_PLAIN); + + return request.get(String.class); + + } + + public T post(String url, Object payload,Class type) { + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); + } + + +} diff --git a/micro-slack/src/main/java/com/aol/micro/server/slack/plugin/SlackPlugin.java b/micro-slack/src/main/java/com/aol/micro/server/slack/plugin/SlackPlugin.java deleted file mode 100644 index 8852ba52a..000000000 --- a/micro-slack/src/main/java/com/aol/micro/server/slack/plugin/SlackPlugin.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.aol.micro.server.slack.plugin; - - -import com.aol.micro.server.Plugin; -import com.aol.micro.server.slack.*; -import cyclops.collections.immutable.PersistentSetX; -import cyclops.collections.mutable.SetX; - -import java.util.Set; - -public class SlackPlugin implements Plugin { - - @Override - public Set springClasses() { - return SetX.of(SlackConfiguration.class, SlackMessageSender.class); - } -} diff --git a/micro-slack/src/main/java/com/aol/micro/server/slack/rest/SlackRest.java b/micro-slack/src/main/java/com/aol/micro/server/slack/rest/SlackRest.java deleted file mode 100644 index 7eaa79788..000000000 --- a/micro-slack/src/main/java/com/aol/micro/server/slack/rest/SlackRest.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.aol.micro.server.slack.rest; - -import java.io.IOException; - -import javax.ws.rs.Consumes; -import javax.ws.rs.POST; -import javax.ws.rs.Path; - -import org.springframework.beans.factory.annotation.Autowired; - -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.slack.SlackConfiguration; -import com.aol.micro.server.slack.SlackMessageSender; - -@Rest -@Path("/slack") -public class SlackRest { - - SlackMessageSender slackMessageSender; - - @Autowired - public SlackRest(SlackConfiguration slackConfiguration){ - slackMessageSender = new SlackMessageSender(slackConfiguration); - } - - @POST - @Path("/message") - @Consumes("application/json") - public String sendMessage(final String msg) { - slackMessageSender.postMessageToSlack(msg); - return "OK"; - } -} diff --git a/micro-slack/src/main/java/com/aol/micro/server/slack/SlackConfiguration.java b/micro-slack/src/main/java/com/oath/micro/server/slack/SlackConfiguration.java similarity index 92% rename from micro-slack/src/main/java/com/aol/micro/server/slack/SlackConfiguration.java rename to micro-slack/src/main/java/com/oath/micro/server/slack/SlackConfiguration.java index 919f7628d..97b5745bb 100644 --- a/micro-slack/src/main/java/com/aol/micro/server/slack/SlackConfiguration.java +++ b/micro-slack/src/main/java/com/oath/micro/server/slack/SlackConfiguration.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.slack; +package com.oath.micro.server.slack; import lombok.Getter; import org.springframework.beans.factory.annotation.Autowired; diff --git a/micro-slack/src/main/java/com/aol/micro/server/slack/SlackMessageSender.java b/micro-slack/src/main/java/com/oath/micro/server/slack/SlackMessageSender.java similarity index 92% rename from micro-slack/src/main/java/com/aol/micro/server/slack/SlackMessageSender.java rename to micro-slack/src/main/java/com/oath/micro/server/slack/SlackMessageSender.java index 5bd656961..2bf9f3c5d 100644 --- a/micro-slack/src/main/java/com/aol/micro/server/slack/SlackMessageSender.java +++ b/micro-slack/src/main/java/com/oath/micro/server/slack/SlackMessageSender.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.slack; +package com.oath.micro.server.slack; import javax.net.ssl.HttpsURLConnection; @@ -8,7 +8,6 @@ import java.io.DataOutputStream; import java.io.IOException; import java.io.InputStreamReader; -import java.net.MalformedURLException; import java.net.URL; import org.springframework.beans.factory.annotation.Autowired; @@ -35,7 +34,7 @@ public int postMessageToSlack(String msg){ //add request header con.setRequestMethod("POST"); - con.setRequestProperty("User-Agent", "com.aol.micro.server"); + con.setRequestProperty("User-Agent", "com.oath.micro.server"); con.setRequestProperty("Content-Type", "application/json"); con.setRequestProperty("Accept-Language", "en-US,en;q=0.5"); diff --git a/micro-slack/src/main/java/com/oath/micro/server/slack/plugin/SlackPlugin.java b/micro-slack/src/main/java/com/oath/micro/server/slack/plugin/SlackPlugin.java new file mode 100644 index 000000000..43fbca279 --- /dev/null +++ b/micro-slack/src/main/java/com/oath/micro/server/slack/plugin/SlackPlugin.java @@ -0,0 +1,16 @@ +package com.oath.micro.server.slack.plugin; + + +import com.oath.micro.server.Plugin; +import com.oath.micro.server.slack.*; +import cyclops.collections.mutable.SetX; + +import java.util.Set; + +public class SlackPlugin implements Plugin { + + @Override + public Set springClasses() { + return SetX.of(SlackConfiguration.class, SlackMessageSender.class); + } +} diff --git a/micro-slack/src/main/java/com/oath/micro/server/slack/rest/SlackRest.java b/micro-slack/src/main/java/com/oath/micro/server/slack/rest/SlackRest.java new file mode 100644 index 000000000..fceed1f73 --- /dev/null +++ b/micro-slack/src/main/java/com/oath/micro/server/slack/rest/SlackRest.java @@ -0,0 +1,31 @@ +package com.oath.micro.server.slack.rest; + +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; + +import org.springframework.beans.factory.annotation.Autowired; + +import com.oath.micro.server.auto.discovery.Rest; +import com.oath.micro.server.slack.SlackConfiguration; +import com.oath.micro.server.slack.SlackMessageSender; + +@Rest +@Path("/slack") +public class SlackRest { + + SlackMessageSender slackMessageSender; + + @Autowired + public SlackRest(SlackConfiguration slackConfiguration){ + slackMessageSender = new SlackMessageSender(slackConfiguration); + } + + @POST + @Path("/message") + @Consumes("application/json") + public String sendMessage(final String msg) { + slackMessageSender.postMessageToSlack(msg); + return "OK"; + } +} diff --git a/micro-slack/src/main/resources/META-INF/services/com.aol.micro.server.Plugin b/micro-slack/src/main/resources/META-INF/services/com.aol.micro.server.Plugin deleted file mode 100644 index bc0c1b2e5..000000000 --- a/micro-slack/src/main/resources/META-INF/services/com.aol.micro.server.Plugin +++ /dev/null @@ -1 +0,0 @@ -com.aol.micro.server.slack.plugin.SlackPlugin diff --git a/micro-slack/src/main/resources/META-INF/services/com.oath.micro.server.Plugin b/micro-slack/src/main/resources/META-INF/services/com.oath.micro.server.Plugin new file mode 100644 index 000000000..84f7efd90 --- /dev/null +++ b/micro-slack/src/main/resources/META-INF/services/com.oath.micro.server.Plugin @@ -0,0 +1 @@ +com.oath.micro.server.slack.plugin.SlackPlugin diff --git a/micro-slack/src/test/java/com/aol/micro/server/slack/SlackMessageSenderTest.java b/micro-slack/src/test/java/com/oath/micro/server/slack/SlackMessageSenderTest.java similarity index 95% rename from micro-slack/src/test/java/com/aol/micro/server/slack/SlackMessageSenderTest.java rename to micro-slack/src/test/java/com/oath/micro/server/slack/SlackMessageSenderTest.java index e5498a4ed..29589eb03 100644 --- a/micro-slack/src/test/java/com/aol/micro/server/slack/SlackMessageSenderTest.java +++ b/micro-slack/src/test/java/com/oath/micro/server/slack/SlackMessageSenderTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.slack; +package com.oath.micro.server.slack; import static org.junit.Assert.assertTrue; diff --git a/micro-slack/src/test/java/com/aol/micro/server/slack/SlackRestTest.java b/micro-slack/src/test/java/com/oath/micro/server/slack/SlackRestTest.java similarity index 93% rename from micro-slack/src/test/java/com/aol/micro/server/slack/SlackRestTest.java rename to micro-slack/src/test/java/com/oath/micro/server/slack/SlackRestTest.java index e4496e1ae..4d2c822a2 100644 --- a/micro-slack/src/test/java/com/aol/micro/server/slack/SlackRestTest.java +++ b/micro-slack/src/test/java/com/oath/micro/server/slack/SlackRestTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.slack; +package com.oath.micro.server.slack; import org.junit.Assert; import org.junit.Before; @@ -13,7 +13,7 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import com.aol.micro.server.slack.rest.SlackRest; +import com.oath.micro.server.slack.rest.SlackRest; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "/context.xml") diff --git a/micro-slack/src/test/java/com/aol/micro/server/slack/SlackRunnerTest.java b/micro-slack/src/test/java/com/oath/micro/server/slack/SlackRunnerTest.java similarity index 89% rename from micro-slack/src/test/java/com/aol/micro/server/slack/SlackRunnerTest.java rename to micro-slack/src/test/java/com/oath/micro/server/slack/SlackRunnerTest.java index 4149166ab..2603bf4f7 100644 --- a/micro-slack/src/test/java/com/aol/micro/server/slack/SlackRunnerTest.java +++ b/micro-slack/src/test/java/com/oath/micro/server/slack/SlackRunnerTest.java @@ -1,12 +1,12 @@ -package com.aol.micro.server.slack; +package com.oath.micro.server.slack; import static com.jayway.restassured.RestAssured.given; import static org.junit.Assert.*; import org.junit.*; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; import com.jayway.restassured.builder.RequestSpecBuilder; import com.jayway.restassured.specification.RequestSpecification; diff --git a/micro-slack/src/test/resources/context.xml b/micro-slack/src/test/resources/context.xml index f49e39421..13479962f 100644 --- a/micro-slack/src/test/resources/context.xml +++ b/micro-slack/src/test/resources/context.xml @@ -16,5 +16,5 @@ - + \ No newline at end of file diff --git a/micro-spring-boot/src/main/java/com/aol/micro/server/spring/boot/BootPlugin.java b/micro-spring-boot/src/main/java/com/aol/micro/server/spring/boot/BootPlugin.java deleted file mode 100644 index ffc648c92..000000000 --- a/micro-spring-boot/src/main/java/com/aol/micro/server/spring/boot/BootPlugin.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.aol.micro.server.spring.boot; - -import java.util.Map; -import java.util.Set; -import java.util.function.Function; - -import javax.ws.rs.core.FeatureContext; - -import cyclops.collections.mutable.MapX; -import cyclops.collections.mutable.SetX; -import cyclops.companion.MapXs; -import cyclops.collections.immutable.PersistentMapX; -import cyclops.collections.immutable.PersistentSetX; -import org.glassfish.jersey.CommonProperties; - - -import com.aol.micro.server.Plugin; -import com.aol.micro.server.rest.jersey.SpringBootJerseyRestApplication; -import com.aol.micro.server.spring.SpringBuilder; - -/** - * - * @author johnmcclean - * - */ -public class BootPlugin implements Plugin{ - - - /** - * @return Engine for building Spring Context - */ - public SpringBuilder springBuilder(){ - return new BootFrontEndApplicationConfigurator(); - } - - @Override - public Set springClasses() { - return SetX.of(SpringBootJerseyRestApplication.class); - } - - - @Override - public Function> jacksonFeatureProperties(){ - return context-> MapX.fromMap(MapXs.of( CommonProperties.MOXY_JSON_FEATURE_DISABLE + '.' - + context.getConfiguration().getRuntimeType().name().toLowerCase(),true)); - } - - - - -} diff --git a/micro-spring-boot/src/main/java/com/aol/micro/server/spring/boot/JerseySpringBootFrontEndApplication.java b/micro-spring-boot/src/main/java/com/aol/micro/server/spring/boot/JerseySpringBootFrontEndApplication.java deleted file mode 100644 index 9f65adbf3..000000000 --- a/micro-spring-boot/src/main/java/com/aol/micro/server/spring/boot/JerseySpringBootFrontEndApplication.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.aol.micro.server.spring.boot; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.Properties; - -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.context.web.SpringBootServletInitializer; -import org.springframework.context.ApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.PropertySource; - -import com.aol.micro.server.module.Environment; -import com.aol.micro.server.servers.AccessLogLocationBean; -import com.aol.micro.server.spring.properties.PropertyFileConfig; - - -@Configuration -@PropertySource("classpath:spring-boot-microserver.properties") -public class JerseySpringBootFrontEndApplication extends SpringBootServletInitializer { - - List classes; - - public JerseySpringBootFrontEndApplication(){ - classes = new ArrayList<>(); - } - - public JerseySpringBootFrontEndApplication(List classes2) { - classes = new ArrayList<>(); - classes.addAll(classes2); - classes.add(JerseySpringBootFrontEndApplication.class); - classes.add(PropertyFileConfig.class); - classes.add(Environment.class); - classes.add(AccessLogLocationBean.class); - } - - - @Override - protected SpringApplicationBuilder configure( - SpringApplicationBuilder application) { - - return application.sources(classes.toArray(new Class[0])); - } - - public SpringApplicationBuilder config(SpringApplicationBuilder builder) { - return configure(builder); - - } - - @Bean - public AccessLogLocationBean createAccessLogLocationBean( - ApplicationContext rootContext) { - Properties props = (Properties) rootContext.getBean("propertyFactory"); - String location = Optional.ofNullable( - (String) props.get("access.log.output")).orElse("./logs/"); - return new AccessLogLocationBean(location); - } - - - - - - - -} diff --git a/micro-spring-boot/src/main/java/com/aol/micro/server/rest/jersey/SpringBootJerseyRestApplication.java b/micro-spring-boot/src/main/java/com/oath/micro/server/rest/jersey/SpringBootJerseyRestApplication.java similarity index 85% rename from micro-spring-boot/src/main/java/com/aol/micro/server/rest/jersey/SpringBootJerseyRestApplication.java rename to micro-spring-boot/src/main/java/com/oath/micro/server/rest/jersey/SpringBootJerseyRestApplication.java index 9142abe69..bb5e616fb 100644 --- a/micro-spring-boot/src/main/java/com/aol/micro/server/rest/jersey/SpringBootJerseyRestApplication.java +++ b/micro-spring-boot/src/main/java/com/oath/micro/server/rest/jersey/SpringBootJerseyRestApplication.java @@ -1,6 +1,5 @@ -package com.aol.micro.server.rest.jersey; +package com.oath.micro.server.rest.jersey; -import java.util.List; import java.util.Map; import cyclops.collections.immutable.LinkedListX; @@ -10,12 +9,12 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; -import com.aol.micro.server.GlobalState; -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.auto.discovery.RestResource; -import com.aol.micro.server.module.JaxRsProvider; -import com.aol.micro.server.module.Module; -import com.aol.micro.server.module.ModuleDataExtractor; +import com.oath.micro.server.GlobalState; +import com.oath.micro.server.auto.discovery.Rest; +import com.oath.micro.server.auto.discovery.RestResource; +import com.oath.micro.server.module.JaxRsProvider; +import com.oath.micro.server.module.Module; +import com.oath.micro.server.module.ModuleDataExtractor; public class SpringBootJerseyRestApplication extends ResourceConfig { diff --git a/micro-spring-boot/src/main/java/com/aol/micro/server/spring/boot/BootFrontEndApplicationConfigurator.java b/micro-spring-boot/src/main/java/com/oath/micro/server/spring/boot/BootFrontEndApplicationConfigurator.java similarity index 84% rename from micro-spring-boot/src/main/java/com/aol/micro/server/spring/boot/BootFrontEndApplicationConfigurator.java rename to micro-spring-boot/src/main/java/com/oath/micro/server/spring/boot/BootFrontEndApplicationConfigurator.java index 62a947cb2..d4eb3cfdb 100644 --- a/micro-spring-boot/src/main/java/com/aol/micro/server/spring/boot/BootFrontEndApplicationConfigurator.java +++ b/micro-spring-boot/src/main/java/com/oath/micro/server/spring/boot/BootFrontEndApplicationConfigurator.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.spring.boot; +package com.oath.micro.server.spring.boot; import java.util.ArrayList; @@ -25,17 +25,17 @@ import org.springframework.web.context.ContextLoader; -import com.aol.micro.server.config.Config; -import com.aol.micro.server.module.Environment; -import com.aol.micro.server.module.Module; -import com.aol.micro.server.module.ModuleDataExtractor; -import com.aol.micro.server.servers.FilterConfigurer; -import com.aol.micro.server.servers.ServletConfigurer; -import com.aol.micro.server.servers.ServletContextListenerConfigurer; -import com.aol.micro.server.servers.model.FilterData; -import com.aol.micro.server.servers.model.ServerData; -import com.aol.micro.server.servers.model.ServletData; -import com.aol.micro.server.spring.SpringBuilder; +import com.oath.micro.server.config.Config; +import com.oath.micro.server.module.Environment; +import com.oath.micro.server.module.Module; +import com.oath.micro.server.module.ModuleDataExtractor; +import com.oath.micro.server.servers.FilterConfigurer; +import com.oath.micro.server.servers.ServletConfigurer; +import com.oath.micro.server.servers.ServletContextListenerConfigurer; +import com.oath.micro.server.servers.model.FilterData; +import com.oath.micro.server.servers.model.ServerData; +import com.oath.micro.server.servers.model.ServletData; +import com.oath.micro.server.spring.SpringBuilder; public class BootFrontEndApplicationConfigurator extends SpringBootServletInitializer implements SpringBuilder { private final Logger logger = LoggerFactory.getLogger(this.getClass()); diff --git a/micro-spring-boot/src/main/java/com/oath/micro/server/spring/boot/BootPlugin.java b/micro-spring-boot/src/main/java/com/oath/micro/server/spring/boot/BootPlugin.java new file mode 100644 index 000000000..1ac3460a3 --- /dev/null +++ b/micro-spring-boot/src/main/java/com/oath/micro/server/spring/boot/BootPlugin.java @@ -0,0 +1,49 @@ +package com.oath.micro.server.spring.boot; + +import java.util.Map; +import java.util.Set; +import java.util.function.Function; + +import javax.ws.rs.core.FeatureContext; + +import cyclops.collections.mutable.MapX; +import cyclops.collections.mutable.SetX; +import cyclops.companion.MapXs; +import org.glassfish.jersey.CommonProperties; + + +import com.oath.micro.server.Plugin; +import com.oath.micro.server.rest.jersey.SpringBootJerseyRestApplication; +import com.oath.micro.server.spring.SpringBuilder; + +/** + * + * @author johnmcclean + * + */ +public class BootPlugin implements Plugin{ + + + /** + * @return Engine for building Spring Context + */ + public SpringBuilder springBuilder(){ + return new BootFrontEndApplicationConfigurator(); + } + + @Override + public Set springClasses() { + return SetX.of(SpringBootJerseyRestApplication.class); + } + + + @Override + public Function> jacksonFeatureProperties(){ + return context-> MapX.fromMap(MapXs.of( CommonProperties.MOXY_JSON_FEATURE_DISABLE + '.' + + context.getConfiguration().getRuntimeType().name().toLowerCase(),true)); + } + + + + +} diff --git a/micro-spring-boot/src/main/java/com/oath/micro/server/spring/boot/JerseySpringBootFrontEndApplication.java b/micro-spring-boot/src/main/java/com/oath/micro/server/spring/boot/JerseySpringBootFrontEndApplication.java new file mode 100644 index 000000000..606b8f16d --- /dev/null +++ b/micro-spring-boot/src/main/java/com/oath/micro/server/spring/boot/JerseySpringBootFrontEndApplication.java @@ -0,0 +1,67 @@ +package com.oath.micro.server.spring.boot; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.Properties; + +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.context.web.SpringBootServletInitializer; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; + +import com.oath.micro.server.module.Environment; +import com.oath.micro.server.servers.AccessLogLocationBean; +import com.oath.micro.server.spring.properties.PropertyFileConfig; + + +@Configuration +@PropertySource("classpath:spring-boot-microserver.properties") +public class JerseySpringBootFrontEndApplication extends SpringBootServletInitializer { + + List classes; + + public JerseySpringBootFrontEndApplication(){ + classes = new ArrayList<>(); + } + + public JerseySpringBootFrontEndApplication(List classes2) { + classes = new ArrayList<>(); + classes.addAll(classes2); + classes.add(JerseySpringBootFrontEndApplication.class); + classes.add(PropertyFileConfig.class); + classes.add(Environment.class); + classes.add(AccessLogLocationBean.class); + } + + + @Override + protected SpringApplicationBuilder configure( + SpringApplicationBuilder application) { + + return application.sources(classes.toArray(new Class[0])); + } + + public SpringApplicationBuilder config(SpringApplicationBuilder builder) { + return configure(builder); + + } + + @Bean + public AccessLogLocationBean createAccessLogLocationBean( + ApplicationContext rootContext) { + Properties props = (Properties) rootContext.getBean("propertyFactory"); + String location = Optional.ofNullable( + (String) props.get("access.log.output")).orElse("./logs/"); + return new AccessLogLocationBean(location); + } + + + + + + + +} diff --git a/micro-spring-boot/src/main/java/com/aol/micro/server/spring/boot/MicroSpringBoot.java b/micro-spring-boot/src/main/java/com/oath/micro/server/spring/boot/MicroSpringBoot.java similarity index 92% rename from micro-spring-boot/src/main/java/com/aol/micro/server/spring/boot/MicroSpringBoot.java rename to micro-spring-boot/src/main/java/com/oath/micro/server/spring/boot/MicroSpringBoot.java index b9b916860..636ddcc04 100644 --- a/micro-spring-boot/src/main/java/com/aol/micro/server/spring/boot/MicroSpringBoot.java +++ b/micro-spring-boot/src/main/java/com/oath/micro/server/spring/boot/MicroSpringBoot.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.spring.boot; +package com.oath.micro.server.spring.boot; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/micro-spring-boot/src/main/resources/META-INF/services/com.aol.micro.server.Plugin b/micro-spring-boot/src/main/resources/META-INF/services/com.aol.micro.server.Plugin deleted file mode 100644 index 3e9503978..000000000 --- a/micro-spring-boot/src/main/resources/META-INF/services/com.aol.micro.server.Plugin +++ /dev/null @@ -1 +0,0 @@ -com.aol.micro.server.spring.boot.BootPlugin \ No newline at end of file diff --git a/micro-spring-boot/src/main/resources/META-INF/services/com.oath.micro.server.Plugin b/micro-spring-boot/src/main/resources/META-INF/services/com.oath.micro.server.Plugin new file mode 100644 index 000000000..e726bf190 --- /dev/null +++ b/micro-spring-boot/src/main/resources/META-INF/services/com.oath.micro.server.Plugin @@ -0,0 +1 @@ +com.oath.micro.server.spring.boot.BootPlugin \ No newline at end of file diff --git a/micro-spring-boot/src/test/java/app/boot/com/aol/micro/server/AsyncAppRunner.java b/micro-spring-boot/src/test/java/app/boot/com/aol/micro/server/AsyncAppRunner.java deleted file mode 100644 index eb720cb1b..000000000 --- a/micro-spring-boot/src/test/java/app/boot/com/aol/micro/server/AsyncAppRunner.java +++ /dev/null @@ -1,38 +0,0 @@ -package app.boot.com.aol.micro.server; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; - -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.rest.client.nio.AsyncRestClient; -import com.aol.micro.server.spring.boot.MicroSpringBoot; - -@Microserver @MicroSpringBoot -public class AsyncAppRunner { - - - AsyncRestClient rest = new AsyncRestClient(1000,1000).withAccept("text/plain"); - - - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - new MicroserverApp( ()-> "async-app"); - Thread.sleep(2000); - - assertThat(rest.get("http://localhost:8080/async-app/async/expensive").get(),is(";test!;test!;test!")); - - } - - - -} \ No newline at end of file diff --git a/micro-spring-boot/src/test/java/app/boot/com/aol/micro/server/AsyncResource.java b/micro-spring-boot/src/test/java/app/boot/com/aol/micro/server/AsyncResource.java deleted file mode 100644 index 9c7f53617..000000000 --- a/micro-spring-boot/src/test/java/app/boot/com/aol/micro/server/AsyncResource.java +++ /dev/null @@ -1,56 +0,0 @@ -package app.boot.com.aol.micro.server; - -import java.util.List; -import java.util.concurrent.CompletableFuture; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.container.AsyncResponse; -import javax.ws.rs.container.Suspended; - -import cyclops.async.SimpleReact; -import org.springframework.stereotype.Component; - - -import com.aol.micro.server.auto.discovery.RestResource; -import com.aol.micro.server.rest.client.nio.AsyncRestClient; -import com.google.common.collect.ImmutableList; - -@Path("/async") -@Component -public class AsyncResource implements RestResource{ - - private final SimpleReact simpleReact =new SimpleReact(); - private final ImmutableList urls = ImmutableList.of("http://localhost:8080/async-app/async/ping2", - "http://localhost:8080/async-app/async/ping", - "http://localhost:8080/async-app/async/ping", - "http://localhost:8080/async-app/async/ping"); - - private final AsyncRestClient client = new AsyncRestClient(1000,1000).withAccept("text/plain"); - - @GET - @Path("/expensive") - @Produces("text/plain") - public void expensive(@Suspended AsyncResponse asyncResponse){ - - simpleReact.fromStream(urls.stream() - .>map(it -> client.get(it))) - .onFail(it -> "") - .peek(it -> - System.out.println(it)) - .allOf(data -> { - System.out.println(data); - return asyncResponse.resume(String.join(";", (List)data)); }); - - } - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "test!"; - } - - -} diff --git a/micro-spring-boot/src/test/java/app/boot/com/aol/micro/server/SimpleApp.java b/micro-spring-boot/src/test/java/app/boot/com/aol/micro/server/SimpleApp.java deleted file mode 100644 index 41cdbc63e..000000000 --- a/micro-spring-boot/src/test/java/app/boot/com/aol/micro/server/SimpleApp.java +++ /dev/null @@ -1,12 +0,0 @@ -package app.boot.com.aol.micro.server; - -import com.aol.micro.server.MicroserverApp; - - -public class SimpleApp { - - public static void main(String[] args){ - new MicroserverApp(()->"test-app").run(); - } - -} diff --git a/micro-spring-boot/src/test/java/app/boot/com/oath/micro/server/AsyncAppRunner.java b/micro-spring-boot/src/test/java/app/boot/com/oath/micro/server/AsyncAppRunner.java new file mode 100644 index 000000000..9e6cd7950 --- /dev/null +++ b/micro-spring-boot/src/test/java/app/boot/com/oath/micro/server/AsyncAppRunner.java @@ -0,0 +1,36 @@ +package app.boot.com.oath.micro.server; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; + +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.rest.client.nio.AsyncRestClient; +import com.oath.micro.server.spring.boot.MicroSpringBoot; + +@Microserver @MicroSpringBoot +public class AsyncAppRunner { + + + AsyncRestClient rest = new AsyncRestClient(1000,1000).withAccept("text/plain"); + + + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + new MicroserverApp( ()-> "async-app"); + Thread.sleep(2000); + + assertThat(rest.get("http://localhost:8080/async-app/async/expensive").get(),is(";test!;test!;test!")); + + } + + + +} \ No newline at end of file diff --git a/micro-spring-boot/src/test/java/app/boot/com/oath/micro/server/AsyncResource.java b/micro-spring-boot/src/test/java/app/boot/com/oath/micro/server/AsyncResource.java new file mode 100644 index 000000000..9acd42c8c --- /dev/null +++ b/micro-spring-boot/src/test/java/app/boot/com/oath/micro/server/AsyncResource.java @@ -0,0 +1,56 @@ +package app.boot.com.oath.micro.server; + +import java.util.List; +import java.util.concurrent.CompletableFuture; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.container.AsyncResponse; +import javax.ws.rs.container.Suspended; + +import cyclops.async.SimpleReact; +import org.springframework.stereotype.Component; + + +import com.oath.micro.server.auto.discovery.RestResource; +import com.oath.micro.server.rest.client.nio.AsyncRestClient; +import com.google.common.collect.ImmutableList; + +@Path("/async") +@Component +public class AsyncResource implements RestResource{ + + private final SimpleReact simpleReact =new SimpleReact(); + private final ImmutableList urls = ImmutableList.of("http://localhost:8080/async-app/async/ping2", + "http://localhost:8080/async-app/async/ping", + "http://localhost:8080/async-app/async/ping", + "http://localhost:8080/async-app/async/ping"); + + private final AsyncRestClient client = new AsyncRestClient(1000,1000).withAccept("text/plain"); + + @GET + @Path("/expensive") + @Produces("text/plain") + public void expensive(@Suspended AsyncResponse asyncResponse){ + + simpleReact.fromStream(urls.stream() + .>map(it -> client.get(it))) + .onFail(it -> "") + .peek(it -> + System.out.println(it)) + .allOf(data -> { + System.out.println(data); + return asyncResponse.resume(String.join(";", (List)data)); }); + + } + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "test!"; + } + + +} diff --git a/micro-spring-boot/src/test/java/app/boot/com/oath/micro/server/SimpleApp.java b/micro-spring-boot/src/test/java/app/boot/com/oath/micro/server/SimpleApp.java new file mode 100644 index 000000000..29820978c --- /dev/null +++ b/micro-spring-boot/src/test/java/app/boot/com/oath/micro/server/SimpleApp.java @@ -0,0 +1,12 @@ +package app.boot.com.oath.micro.server; + +import com.oath.micro.server.MicroserverApp; + + +public class SimpleApp { + + public static void main(String[] args){ + new MicroserverApp(()->"test-app").run(); + } + +} diff --git a/micro-spring-boot/src/test/java/app/boot/events/com/aol/micro/server/EventRunnerTest.java b/micro-spring-boot/src/test/java/app/boot/events/com/aol/micro/server/EventRunnerTest.java deleted file mode 100644 index 75990110a..000000000 --- a/micro-spring-boot/src/test/java/app/boot/events/com/aol/micro/server/EventRunnerTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package app.boot.events.com.aol.micro.server; - - -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.rest.client.nio.AsyncRestClient; -import com.aol.micro.server.testing.RestAgent; -import com.aol.micro.server.spring.boot.MicroSpringBoot; - -@Microserver -@MicroSpringBoot -public class EventRunnerTest { - - RestAgent rest = new RestAgent(); - private final AsyncRestClient client = new AsyncRestClient(1000,1000).withAccept("application/json"); - MicroserverApp server; - - - @Before - public void startServer(){ - - server = new MicroserverApp(()-> "event-app"); - - - } - - - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - - - assertThat(rest.get("http://localhost:8080/event-app/status/ping"),is("ok")); - - assertThat(client.get("http://localhost:8080/event-app/active/jobs").get(), - containsString("startedAt")); - assertThat(client.get("http://localhost:8080/event-app/active/requests").get(), - containsString("startedAt")); -// assertThat(client.get("http://localhost:8080/event-app/manifest").get(), -// containsString("Manifest")); - - } - - - -} diff --git a/micro-spring-boot/src/test/java/app/boot/events/com/aol/micro/server/EventStatusResource.java b/micro-spring-boot/src/test/java/app/boot/events/com/aol/micro/server/EventStatusResource.java deleted file mode 100644 index 4a17b5de9..000000000 --- a/micro-spring-boot/src/test/java/app/boot/events/com/aol/micro/server/EventStatusResource.java +++ /dev/null @@ -1,40 +0,0 @@ -package app.boot.events.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.RestResource; -import com.aol.micro.server.events.RequestEvents; -import com.google.common.eventbus.EventBus; - -@Component -@Path("/status") -public class EventStatusResource implements RestResource { - - - - - private final EventBus bus; - - @Autowired - public EventStatusResource(EventBus bus ){ - this.bus = bus; - } - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - bus.post(RequestEvents.start("get", 1l)); - try{ - return "ok"; - }finally{ - bus.post(RequestEvents.finish("get",1l)); - } - } - -} \ No newline at end of file diff --git a/micro-spring-boot/src/test/java/app/boot/events/com/aol/micro/server/Job.java b/micro-spring-boot/src/test/java/app/boot/events/com/aol/micro/server/Job.java deleted file mode 100644 index 8978963fd..000000000 --- a/micro-spring-boot/src/test/java/app/boot/events/com/aol/micro/server/Job.java +++ /dev/null @@ -1,16 +0,0 @@ -package app.boot.events.com.aol.micro.server; - -import org.springframework.stereotype.Component; - -import com.aol.micro.server.events.ScheduledJob; -import com.aol.micro.server.events.SystemData; - -@Component -public class Job implements ScheduledJob{ - - @Override - public SystemData scheduleAndLog() { - return SystemData.builder().errors(0).processed(2).build(); - } - -} diff --git a/micro-spring-boot/src/test/java/app/boot/events/com/aol/micro/server/Schedular.java b/micro-spring-boot/src/test/java/app/boot/events/com/aol/micro/server/Schedular.java deleted file mode 100644 index d68afd75c..000000000 --- a/micro-spring-boot/src/test/java/app/boot/events/com/aol/micro/server/Schedular.java +++ /dev/null @@ -1,22 +0,0 @@ -package app.boot.events.com.aol.micro.server; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Component; - - -@Component -public class Schedular { - - private final Job job; - - @Autowired - public Schedular(final Job job){ - this.job=job; - } - - @Scheduled(fixedDelay=1) - public synchronized void scheduleTask(){ - job.scheduleAndLog(); - } -} diff --git a/micro-spring-boot/src/test/java/app/boot/events/com/oath/micro/server/EventRunnerTest.java b/micro-spring-boot/src/test/java/app/boot/events/com/oath/micro/server/EventRunnerTest.java new file mode 100644 index 000000000..3599ebc9c --- /dev/null +++ b/micro-spring-boot/src/test/java/app/boot/events/com/oath/micro/server/EventRunnerTest.java @@ -0,0 +1,56 @@ +package app.boot.events.com.oath.micro.server; + + +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.rest.client.nio.AsyncRestClient; +import com.oath.micro.server.testing.RestAgent; +import com.oath.micro.server.spring.boot.MicroSpringBoot; + +@Microserver +@MicroSpringBoot +public class EventRunnerTest { + + RestAgent rest = new RestAgent(); + private final AsyncRestClient client = new AsyncRestClient(1000,1000).withAccept("application/json"); + MicroserverApp server; + + + @Before + public void startServer(){ + + server = new MicroserverApp(()-> "event-app"); + + + } + + + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + + + assertThat(rest.get("http://localhost:8080/event-app/status/ping"),is("ok")); + + assertThat(client.get("http://localhost:8080/event-app/active/jobs").get(), + containsString("startedAt")); + assertThat(client.get("http://localhost:8080/event-app/active/requests").get(), + containsString("startedAt")); +// assertThat(client.get("http://localhost:8080/event-app/manifest").get(), +// containsString("Manifest")); + + } + + + +} diff --git a/micro-spring-boot/src/test/java/app/boot/events/com/oath/micro/server/EventStatusResource.java b/micro-spring-boot/src/test/java/app/boot/events/com/oath/micro/server/EventStatusResource.java new file mode 100644 index 000000000..fadef80d6 --- /dev/null +++ b/micro-spring-boot/src/test/java/app/boot/events/com/oath/micro/server/EventStatusResource.java @@ -0,0 +1,40 @@ +package app.boot.events.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.RestResource; +import com.oath.micro.server.events.RequestEvents; +import com.google.common.eventbus.EventBus; + +@Component +@Path("/status") +public class EventStatusResource implements RestResource { + + + + + private final EventBus bus; + + @Autowired + public EventStatusResource(EventBus bus ){ + this.bus = bus; + } + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + bus.post(RequestEvents.start("get", 1l)); + try{ + return "ok"; + }finally{ + bus.post(RequestEvents.finish("get",1l)); + } + } + +} \ No newline at end of file diff --git a/micro-spring-boot/src/test/java/app/boot/events/com/oath/micro/server/Job.java b/micro-spring-boot/src/test/java/app/boot/events/com/oath/micro/server/Job.java new file mode 100644 index 000000000..733a8c2ae --- /dev/null +++ b/micro-spring-boot/src/test/java/app/boot/events/com/oath/micro/server/Job.java @@ -0,0 +1,16 @@ +package app.boot.events.com.oath.micro.server; + +import org.springframework.stereotype.Component; + +import com.oath.micro.server.events.ScheduledJob; +import com.oath.micro.server.events.SystemData; + +@Component +public class Job implements ScheduledJob{ + + @Override + public SystemData scheduleAndLog() { + return SystemData.builder().errors(0).processed(2).build(); + } + +} diff --git a/micro-spring-boot/src/test/java/app/boot/events/com/oath/micro/server/Schedular.java b/micro-spring-boot/src/test/java/app/boot/events/com/oath/micro/server/Schedular.java new file mode 100644 index 000000000..a14db58f9 --- /dev/null +++ b/micro-spring-boot/src/test/java/app/boot/events/com/oath/micro/server/Schedular.java @@ -0,0 +1,22 @@ +package app.boot.events.com.oath.micro.server; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + + +@Component +public class Schedular { + + private final Job job; + + @Autowired + public Schedular(final Job job){ + this.job=job; + } + + @Scheduled(fixedDelay=1) + public synchronized void scheduleTask(){ + job.scheduleAndLog(); + } +} diff --git a/micro-spring-boot/src/test/java/app/boot/front/end/SampleJerseyApplication.java b/micro-spring-boot/src/test/java/app/boot/front/end/SampleJerseyApplication.java index c31f28042..a3ca87135 100644 --- a/micro-spring-boot/src/test/java/app/boot/front/end/SampleJerseyApplication.java +++ b/micro-spring-boot/src/test/java/app/boot/front/end/SampleJerseyApplication.java @@ -1,8 +1,8 @@ package app.boot.front.end; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.spring.boot.MicroSpringBoot; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.spring.boot.MicroSpringBoot; @Microserver @MicroSpringBoot diff --git a/micro-spring-boot/src/test/java/app/boot/front/end/SimpleStatusResource.java b/micro-spring-boot/src/test/java/app/boot/front/end/SimpleStatusResource.java index f2721e392..84c4dea93 100644 --- a/micro-spring-boot/src/test/java/app/boot/front/end/SimpleStatusResource.java +++ b/micro-spring-boot/src/test/java/app/boot/front/end/SimpleStatusResource.java @@ -7,7 +7,7 @@ import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Component; -import com.aol.micro.server.auto.discovery.RestResource; +import com.oath.micro.server.auto.discovery.RestResource; @Component @Qualifier("simpleStatusResource") diff --git a/micro-spring-boot/src/test/java/app/boot/front/end/SimpleTest.java b/micro-spring-boot/src/test/java/app/boot/front/end/SimpleTest.java index 0ec77f91b..345cdad63 100644 --- a/micro-spring-boot/src/test/java/app/boot/front/end/SimpleTest.java +++ b/micro-spring-boot/src/test/java/app/boot/front/end/SimpleTest.java @@ -6,7 +6,7 @@ import org.junit.Test; import org.springframework.beans.factory.annotation.Value; -import com.aol.micro.server.testing.RestAgent; +import com.oath.micro.server.testing.RestAgent; public class SimpleTest { diff --git a/micro-spring-boot/src/test/java/app/custom/binder/direct/BinderDirectTest.java b/micro-spring-boot/src/test/java/app/custom/binder/direct/BinderDirectTest.java index 1d22a4200..5aa46d39f 100644 --- a/micro-spring-boot/src/test/java/app/custom/binder/direct/BinderDirectTest.java +++ b/micro-spring-boot/src/test/java/app/custom/binder/direct/BinderDirectTest.java @@ -12,12 +12,10 @@ import org.junit.Test; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.module.Module; -import com.aol.micro.server.spring.boot.MicroSpringBoot; -import com.aol.micro.server.testing.RestAgent; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.module.ConfigurableModule; +import com.oath.micro.server.spring.boot.MicroSpringBoot; +import com.oath.micro.server.testing.RestAgent; @MicroSpringBoot public class BinderDirectTest { diff --git a/micro-spring-boot/src/test/java/app/custom/binder/direct/CustomBinder4.java b/micro-spring-boot/src/test/java/app/custom/binder/direct/CustomBinder4.java index 9c2b15310..1cd4458e0 100644 --- a/micro-spring-boot/src/test/java/app/custom/binder/direct/CustomBinder4.java +++ b/micro-spring-boot/src/test/java/app/custom/binder/direct/CustomBinder4.java @@ -2,8 +2,6 @@ import org.glassfish.hk2.utilities.binding.AbstractBinder; import org.glassfish.jersey.server.spi.internal.ResourceMethodInvocationHandlerProvider; -import com.aol.micro.server.auto.discovery.JaxRsResource; - public class CustomBinder4 extends AbstractBinder { @Override diff --git a/micro-spring-boot/src/test/java/app/custom/binder/direct/SimpleApp.java b/micro-spring-boot/src/test/java/app/custom/binder/direct/SimpleApp.java index 95150b9e9..b909890af 100644 --- a/micro-spring-boot/src/test/java/app/custom/binder/direct/SimpleApp.java +++ b/micro-spring-boot/src/test/java/app/custom/binder/direct/SimpleApp.java @@ -3,12 +3,7 @@ import javax.ws.rs.GET; import javax.ws.rs.Path; -import org.glassfish.jersey.server.ResourceConfig; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.module.ConfigurableModule; - +import com.oath.micro.server.auto.discovery.Rest; @Rest diff --git a/micro-spring-boot/src/test/java/app/custom/binder/noanno/BinderTest.java b/micro-spring-boot/src/test/java/app/custom/binder/noanno/BinderTest.java index efa7a605d..364a6ec0a 100644 --- a/micro-spring-boot/src/test/java/app/custom/binder/noanno/BinderTest.java +++ b/micro-spring-boot/src/test/java/app/custom/binder/noanno/BinderTest.java @@ -10,10 +10,9 @@ import org.junit.Before; import org.junit.Test; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.spring.boot.MicroSpringBoot; -import com.aol.micro.server.testing.RestAgent; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.spring.boot.MicroSpringBoot; +import com.oath.micro.server.testing.RestAgent; @MicroSpringBoot public class BinderTest { diff --git a/micro-spring-boot/src/test/java/app/custom/binder/noanno/Config.java b/micro-spring-boot/src/test/java/app/custom/binder/noanno/Config.java index 024b965a7..3bafd3e1b 100644 --- a/micro-spring-boot/src/test/java/app/custom/binder/noanno/Config.java +++ b/micro-spring-boot/src/test/java/app/custom/binder/noanno/Config.java @@ -3,7 +3,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import com.aol.micro.server.auto.discovery.JaxRsResourceWrapper; +import com.oath.micro.server.auto.discovery.JaxRsResourceWrapper; @Configuration public class Config { diff --git a/micro-spring-boot/src/test/java/app/custom/binder/noanno/CustomBinder2.java b/micro-spring-boot/src/test/java/app/custom/binder/noanno/CustomBinder2.java index e42284b21..706ab300e 100644 --- a/micro-spring-boot/src/test/java/app/custom/binder/noanno/CustomBinder2.java +++ b/micro-spring-boot/src/test/java/app/custom/binder/noanno/CustomBinder2.java @@ -2,8 +2,6 @@ import org.glassfish.hk2.utilities.binding.AbstractBinder; import org.glassfish.jersey.server.spi.internal.ResourceMethodInvocationHandlerProvider; -import com.aol.micro.server.auto.discovery.JaxRsResource; - public class CustomBinder2 extends AbstractBinder { @Override diff --git a/micro-spring-boot/src/test/java/app/custom/binder/noanno/SimpleApp.java b/micro-spring-boot/src/test/java/app/custom/binder/noanno/SimpleApp.java index bfa784520..62668fa46 100644 --- a/micro-spring-boot/src/test/java/app/custom/binder/noanno/SimpleApp.java +++ b/micro-spring-boot/src/test/java/app/custom/binder/noanno/SimpleApp.java @@ -3,12 +3,7 @@ import javax.ws.rs.GET; import javax.ws.rs.Path; -import org.glassfish.jersey.server.ResourceConfig; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.module.ConfigurableModule; - +import com.oath.micro.server.auto.discovery.Rest; @Rest diff --git a/micro-spring-boot/src/test/java/app/custom/binder/resource/objects/BinderTest.java b/micro-spring-boot/src/test/java/app/custom/binder/resource/objects/BinderTest.java index 211aa2052..6d1e26d92 100644 --- a/micro-spring-boot/src/test/java/app/custom/binder/resource/objects/BinderTest.java +++ b/micro-spring-boot/src/test/java/app/custom/binder/resource/objects/BinderTest.java @@ -6,18 +6,15 @@ import java.util.concurrent.ExecutionException; -import cyclops.collections.immutable.PersistentSetX; import cyclops.collections.mutable.SetX; import org.junit.After; import org.junit.Before; import org.junit.Test; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.module.Module; -import com.aol.micro.server.spring.boot.MicroSpringBoot; -import com.aol.micro.server.testing.RestAgent; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.module.ConfigurableModule; +import com.oath.micro.server.spring.boot.MicroSpringBoot; +import com.oath.micro.server.testing.RestAgent; @MicroSpringBoot public class BinderTest { diff --git a/micro-spring-boot/src/test/java/app/custom/binder/resource/objects/CustomBinder3.java b/micro-spring-boot/src/test/java/app/custom/binder/resource/objects/CustomBinder3.java index b10bf9ce1..c08aed638 100644 --- a/micro-spring-boot/src/test/java/app/custom/binder/resource/objects/CustomBinder3.java +++ b/micro-spring-boot/src/test/java/app/custom/binder/resource/objects/CustomBinder3.java @@ -2,8 +2,6 @@ import org.glassfish.hk2.utilities.binding.AbstractBinder; import org.glassfish.jersey.server.spi.internal.ResourceMethodInvocationHandlerProvider; -import com.aol.micro.server.auto.discovery.JaxRsResource; - public class CustomBinder3 extends AbstractBinder { @Override diff --git a/micro-spring-boot/src/test/java/app/custom/binder/resource/objects/SimpleApp.java b/micro-spring-boot/src/test/java/app/custom/binder/resource/objects/SimpleApp.java index 84728cf63..36a9da879 100644 --- a/micro-spring-boot/src/test/java/app/custom/binder/resource/objects/SimpleApp.java +++ b/micro-spring-boot/src/test/java/app/custom/binder/resource/objects/SimpleApp.java @@ -3,12 +3,7 @@ import javax.ws.rs.GET; import javax.ws.rs.Path; -import org.glassfish.jersey.server.ResourceConfig; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.module.ConfigurableModule; - +import com.oath.micro.server.auto.discovery.Rest; @Rest diff --git a/micro-spring-boot/src/test/java/app/custom/binder/test/BinderTest.java b/micro-spring-boot/src/test/java/app/custom/binder/test/BinderTest.java index ad88c931e..419777590 100644 --- a/micro-spring-boot/src/test/java/app/custom/binder/test/BinderTest.java +++ b/micro-spring-boot/src/test/java/app/custom/binder/test/BinderTest.java @@ -3,19 +3,15 @@ import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.*; -import java.util.Arrays; import java.util.concurrent.ExecutionException; -import org.glassfish.jersey.media.multipart.MultiPartFeature; import org.junit.After; import org.junit.Before; import org.junit.Test; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.spring.boot.MicroSpringBoot; -import com.aol.micro.server.testing.RestAgent; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.spring.boot.MicroSpringBoot; +import com.oath.micro.server.testing.RestAgent; @MicroSpringBoot public class BinderTest { diff --git a/micro-spring-boot/src/test/java/app/custom/binder/test/CustomBinder.java b/micro-spring-boot/src/test/java/app/custom/binder/test/CustomBinder.java index 0e23b79a7..299a46bf4 100644 --- a/micro-spring-boot/src/test/java/app/custom/binder/test/CustomBinder.java +++ b/micro-spring-boot/src/test/java/app/custom/binder/test/CustomBinder.java @@ -2,7 +2,7 @@ import org.glassfish.hk2.utilities.binding.AbstractBinder; import org.glassfish.jersey.server.spi.internal.ResourceMethodInvocationHandlerProvider; -import com.aol.micro.server.auto.discovery.JaxRsResource; +import com.oath.micro.server.auto.discovery.JaxRsResource; @JaxRsResource public class CustomBinder extends AbstractBinder { diff --git a/micro-spring-boot/src/test/java/app/custom/binder/test/SimpleApp.java b/micro-spring-boot/src/test/java/app/custom/binder/test/SimpleApp.java index 7a2c74e08..2e275f0bd 100644 --- a/micro-spring-boot/src/test/java/app/custom/binder/test/SimpleApp.java +++ b/micro-spring-boot/src/test/java/app/custom/binder/test/SimpleApp.java @@ -5,9 +5,9 @@ import org.glassfish.jersey.server.ResourceConfig; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.module.ConfigurableModule; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.auto.discovery.Rest; +import com.oath.micro.server.module.ConfigurableModule; diff --git a/micro-spring-boot/src/test/java/app/ebay/com/aol/micro/server/CorsResource.java b/micro-spring-boot/src/test/java/app/ebay/com/oath/micro/server/CorsResource.java similarity index 75% rename from micro-spring-boot/src/test/java/app/ebay/com/aol/micro/server/CorsResource.java rename to micro-spring-boot/src/test/java/app/ebay/com/oath/micro/server/CorsResource.java index 391647a0e..12d9ee641 100644 --- a/micro-spring-boot/src/test/java/app/ebay/com/aol/micro/server/CorsResource.java +++ b/micro-spring-boot/src/test/java/app/ebay/com/oath/micro/server/CorsResource.java @@ -1,4 +1,4 @@ -package app.ebay.com.aol.micro.server; +package app.ebay.com.oath.micro.server; import javax.ws.rs.GET; import javax.ws.rs.Path; @@ -6,7 +6,7 @@ import org.springframework.stereotype.Component; -import com.aol.micro.server.auto.discovery.RestResource; +import com.oath.micro.server.auto.discovery.RestResource; @Path("/single") @Component diff --git a/micro-spring-boot/src/test/java/app/ebay/com/aol/micro/server/FilterTest.java b/micro-spring-boot/src/test/java/app/ebay/com/oath/micro/server/FilterTest.java similarity index 83% rename from micro-spring-boot/src/test/java/app/ebay/com/aol/micro/server/FilterTest.java rename to micro-spring-boot/src/test/java/app/ebay/com/oath/micro/server/FilterTest.java index b9cb01e19..c618b6501 100644 --- a/micro-spring-boot/src/test/java/app/ebay/com/aol/micro/server/FilterTest.java +++ b/micro-spring-boot/src/test/java/app/ebay/com/oath/micro/server/FilterTest.java @@ -1,4 +1,4 @@ -package app.ebay.com.aol.micro.server; +package app.ebay.com.oath.micro.server; import static org.junit.Assert.assertFalse; @@ -16,10 +16,10 @@ import org.junit.Ignore; import org.junit.Test; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.spring.boot.MicroSpringBoot; -import com.aol.micro.server.testing.RestAgent; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.spring.boot.MicroSpringBoot; +import com.oath.micro.server.testing.RestAgent; @Microserver @MicroSpringBoot diff --git a/micro-spring-boot/src/test/java/app/guava/com/aol/micro/server/GuavaAppResource.java b/micro-spring-boot/src/test/java/app/guava/com/aol/micro/server/GuavaAppResource.java deleted file mode 100644 index baeb5aed2..000000000 --- a/micro-spring-boot/src/test/java/app/guava/com/aol/micro/server/GuavaAppResource.java +++ /dev/null @@ -1,30 +0,0 @@ -package app.guava.com.aol.micro.server; - -import java.util.List; -import java.util.Optional; - -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.RestResource; -@Component -@Path("/status") -public class GuavaAppResource implements RestResource { - - @POST - @Produces("application/json") - @Path("/ping") - public List ping(ImmutableGuavaEntity entity) { - return entity.getList(); - } - @POST - @Produces("application/json") - @Path("/optional") - public Optional optional(Jdk8Entity entity) { - return entity.getName(); - } - -} diff --git a/micro-spring-boot/src/test/java/app/guava/com/aol/micro/server/GuavaAppTest.java b/micro-spring-boot/src/test/java/app/guava/com/aol/micro/server/GuavaAppTest.java deleted file mode 100644 index bbd775cab..000000000 --- a/micro-spring-boot/src/test/java/app/guava/com/aol/micro/server/GuavaAppTest.java +++ /dev/null @@ -1,91 +0,0 @@ -package app.guava.com.aol.micro.server; - -import static org.hamcrest.Matchers.hasItem; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - -import java.util.List; -import java.util.Optional; -import java.util.concurrent.ExecutionException; - -import com.oath.cyclops.types.futurestream.SimpleReactStream; -import cyclops.async.SimpleReact; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.rest.jackson.JacksonUtil; -import com.aol.micro.server.spring.boot.MicroSpringBoot; -import com.aol.micro.server.testing.RestAgent; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMultimap; -import com.google.common.collect.ImmutableSet; -@Microserver @MicroSpringBoot -public class GuavaAppTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - - ImmutableGuavaEntity entity; - Jdk8Entity present; - Jdk8Entity absent; - - SimpleReact simpleReact = new SimpleReact(); - SimpleReactStream stream; - - boolean run = false; - @Before - public void startServer() { - if(run) - return; - run =true; - stream = simpleReact.ofAsync( - () -> server = new MicroserverApp(GuavaAppTest.class, - () -> "guava-app")); - - entity = ImmutableGuavaEntity.builder().value("value") - .list(ImmutableList.of("hello", "world")) - .mapOfSets(ImmutableMap.of("key1", ImmutableSet.of(1, 2, 3))) - .multiMap(ImmutableMultimap.of("1", 2, "1", 2, "2", 4)).build(); - - JacksonUtil.convertFromJson(JacksonUtil.serializeToJson(entity), - ImmutableGuavaEntity.class); - - present = Jdk8Entity.builder().name(Optional.of("test")).build(); - - JacksonUtil.convertFromJson(JacksonUtil.serializeToJson(present), - Optional.class); - absent = Jdk8Entity.builder().name(Optional.empty()).build(); - } - - - @Test - public void confirmExpectedUrlsPresentTest() throws InterruptedException, - ExecutionException { - - stream.block(); - - assertThat((List) rest.post( - "http://localhost:8080/guava-app/status/ping", entity, - List.class), hasItem("hello")); - - } - - @Test - public void confirmOptionalConversionWorking() throws InterruptedException, - ExecutionException { - - stream.block(); - - assertThat(rest.post("http://localhost:8080/guava-app/status/optional", - present, String.class), is("\"test\"")); - - assertThat(rest.post("http://localhost:8080/guava-app/status/optional", - absent, String.class), is("null")); - - } - -} diff --git a/micro-spring-boot/src/test/java/app/guava/com/aol/micro/server/ImmutableGuavaEntity.java b/micro-spring-boot/src/test/java/app/guava/com/aol/micro/server/ImmutableGuavaEntity.java deleted file mode 100644 index 7c6294547..000000000 --- a/micro-spring-boot/src/test/java/app/guava/com/aol/micro/server/ImmutableGuavaEntity.java +++ /dev/null @@ -1,34 +0,0 @@ -package app.guava.com.aol.micro.server; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Builder; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMultimap; -import com.google.common.collect.ImmutableSet; - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "") -@XmlRootElement(name = "immutable") -@Getter -@AllArgsConstructor -@Builder -public class ImmutableGuavaEntity { - - private final String value; - private final ImmutableList list; - private final ImmutableMap mapOfSets; - private final ImmutableMultimap multiMap; - - public ImmutableGuavaEntity() { - this(null,null,null,null); - } - -} diff --git a/micro-spring-boot/src/test/java/app/guava/com/aol/micro/server/Jdk8Entity.java b/micro-spring-boot/src/test/java/app/guava/com/aol/micro/server/Jdk8Entity.java deleted file mode 100644 index 722e5cafb..000000000 --- a/micro-spring-boot/src/test/java/app/guava/com/aol/micro/server/Jdk8Entity.java +++ /dev/null @@ -1,27 +0,0 @@ -package app.guava.com.aol.micro.server; - -import java.util.Optional; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Builder; - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "") -@XmlRootElement(name = "optional") -@Getter -@AllArgsConstructor -@Builder -public class Jdk8Entity { - - private final Optional name; - - public Jdk8Entity(){ - name = Optional.empty(); - } -} diff --git a/micro-spring-boot/src/test/java/app/guava/com/oath/micro/server/GuavaAppResource.java b/micro-spring-boot/src/test/java/app/guava/com/oath/micro/server/GuavaAppResource.java new file mode 100644 index 000000000..cce09ece4 --- /dev/null +++ b/micro-spring-boot/src/test/java/app/guava/com/oath/micro/server/GuavaAppResource.java @@ -0,0 +1,30 @@ +package app.guava.com.oath.micro.server; + +import java.util.List; +import java.util.Optional; + +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.RestResource; +@Component +@Path("/status") +public class GuavaAppResource implements RestResource { + + @POST + @Produces("application/json") + @Path("/ping") + public List ping(ImmutableGuavaEntity entity) { + return entity.getList(); + } + @POST + @Produces("application/json") + @Path("/optional") + public Optional optional(Jdk8Entity entity) { + return entity.getName(); + } + +} diff --git a/micro-spring-boot/src/test/java/app/guava/com/oath/micro/server/GuavaAppTest.java b/micro-spring-boot/src/test/java/app/guava/com/oath/micro/server/GuavaAppTest.java new file mode 100644 index 000000000..36a91b609 --- /dev/null +++ b/micro-spring-boot/src/test/java/app/guava/com/oath/micro/server/GuavaAppTest.java @@ -0,0 +1,91 @@ +package app.guava.com.oath.micro.server; + +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + +import java.util.List; +import java.util.Optional; +import java.util.concurrent.ExecutionException; + +import com.oath.cyclops.types.futurestream.SimpleReactStream; +import cyclops.async.SimpleReact; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.rest.jackson.JacksonUtil; +import com.oath.micro.server.spring.boot.MicroSpringBoot; +import com.oath.micro.server.testing.RestAgent; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableMultimap; +import com.google.common.collect.ImmutableSet; +@Microserver @MicroSpringBoot +public class GuavaAppTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + + ImmutableGuavaEntity entity; + Jdk8Entity present; + Jdk8Entity absent; + + SimpleReact simpleReact = new SimpleReact(); + SimpleReactStream stream; + + boolean run = false; + @Before + public void startServer() { + if(run) + return; + run =true; + stream = simpleReact.ofAsync( + () -> server = new MicroserverApp(GuavaAppTest.class, + () -> "guava-app")); + + entity = ImmutableGuavaEntity.builder().value("value") + .list(ImmutableList.of("hello", "world")) + .mapOfSets(ImmutableMap.of("key1", ImmutableSet.of(1, 2, 3))) + .multiMap(ImmutableMultimap.of("1", 2, "1", 2, "2", 4)).build(); + + JacksonUtil.convertFromJson(JacksonUtil.serializeToJson(entity), + ImmutableGuavaEntity.class); + + present = Jdk8Entity.builder().name(Optional.of("test")).build(); + + JacksonUtil.convertFromJson(JacksonUtil.serializeToJson(present), + Optional.class); + absent = Jdk8Entity.builder().name(Optional.empty()).build(); + } + + + @Test + public void confirmExpectedUrlsPresentTest() throws InterruptedException, + ExecutionException { + + stream.block(); + + assertThat((List) rest.post( + "http://localhost:8080/guava-app/status/ping", entity, + List.class), hasItem("hello")); + + } + + @Test + public void confirmOptionalConversionWorking() throws InterruptedException, + ExecutionException { + + stream.block(); + + assertThat(rest.post("http://localhost:8080/guava-app/status/optional", + present, String.class), is("\"test\"")); + + assertThat(rest.post("http://localhost:8080/guava-app/status/optional", + absent, String.class), is("null")); + + } + +} diff --git a/micro-spring-boot/src/test/java/app/guava/com/oath/micro/server/ImmutableGuavaEntity.java b/micro-spring-boot/src/test/java/app/guava/com/oath/micro/server/ImmutableGuavaEntity.java new file mode 100644 index 000000000..e4e706907 --- /dev/null +++ b/micro-spring-boot/src/test/java/app/guava/com/oath/micro/server/ImmutableGuavaEntity.java @@ -0,0 +1,34 @@ +package app.guava.com.oath.micro.server; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Builder; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableMultimap; +import com.google.common.collect.ImmutableSet; + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "") +@XmlRootElement(name = "immutable") +@Getter +@AllArgsConstructor +@Builder +public class ImmutableGuavaEntity { + + private final String value; + private final ImmutableList list; + private final ImmutableMap mapOfSets; + private final ImmutableMultimap multiMap; + + public ImmutableGuavaEntity() { + this(null,null,null,null); + } + +} diff --git a/micro-spring-boot/src/test/java/app/guava/com/oath/micro/server/Jdk8Entity.java b/micro-spring-boot/src/test/java/app/guava/com/oath/micro/server/Jdk8Entity.java new file mode 100644 index 000000000..df2b8662e --- /dev/null +++ b/micro-spring-boot/src/test/java/app/guava/com/oath/micro/server/Jdk8Entity.java @@ -0,0 +1,27 @@ +package app.guava.com.oath.micro.server; + +import java.util.Optional; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Builder; + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "") +@XmlRootElement(name = "optional") +@Getter +@AllArgsConstructor +@Builder +public class Jdk8Entity { + + private final Optional name; + + public Jdk8Entity(){ + name = Optional.empty(); + } +} diff --git a/micro-spring-boot/src/test/java/app/metrics/boot/com/aol/micro/server/MetricsRunnerTest.java b/micro-spring-boot/src/test/java/app/metrics/boot/com/aol/micro/server/MetricsRunnerTest.java deleted file mode 100644 index 1c8591487..000000000 --- a/micro-spring-boot/src/test/java/app/metrics/boot/com/aol/micro/server/MetricsRunnerTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package app.metrics.boot.com.aol.micro.server; - - -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - -import java.io.IOException; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; - -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.spring.boot.MicroSpringBoot; -import com.aol.micro.server.spring.metrics.CodahaleMetricsConfigurer; -import com.aol.micro.server.testing.RestAgent; - -@MicroSpringBoot @Microserver -public class MetricsRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer(){ - CodahaleMetricsConfigurer.setInit( metricRegistry -> TestReporter - .forRegistry(metricRegistry) - .build() - .start(10, TimeUnit.MILLISECONDS)); - - server = new MicroserverApp( ()-> "simple-app"); - - - } - - - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException, IOException{ - - - - - - assertThat(rest.get("http://localhost:8080/simple-app/metrics/ping"),is("ok")); - - - assertThat(TestReporter.getTimer().size(),greaterThan(0)); - } - - - -} diff --git a/micro-spring-boot/src/test/java/app/metrics/boot/com/aol/micro/server/MetricsStatusResource.java b/micro-spring-boot/src/test/java/app/metrics/boot/com/aol/micro/server/MetricsStatusResource.java deleted file mode 100644 index 48bd138ee..000000000 --- a/micro-spring-boot/src/test/java/app/metrics/boot/com/aol/micro/server/MetricsStatusResource.java +++ /dev/null @@ -1,28 +0,0 @@ -package app.metrics.boot.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - - - -import com.aol.micro.server.auto.discovery.RestResource; - -@Component -@Path("/metrics") -public class MetricsStatusResource implements RestResource { - - @Autowired - TimedResource timed; - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - timed.times(); - return "ok"; - } - -} \ No newline at end of file diff --git a/micro-spring-boot/src/test/java/app/metrics/boot/com/aol/micro/server/TestReporter.java b/micro-spring-boot/src/test/java/app/metrics/boot/com/aol/micro/server/TestReporter.java deleted file mode 100644 index a75b93ca4..000000000 --- a/micro-spring-boot/src/test/java/app/metrics/boot/com/aol/micro/server/TestReporter.java +++ /dev/null @@ -1,169 +0,0 @@ -package app.metrics.boot.com.aol.micro.server; - -import java.io.PrintStream; -import java.util.Locale; -import java.util.SortedMap; -import java.util.TimeZone; -import java.util.TreeMap; -import java.util.concurrent.TimeUnit; - -import lombok.Getter; - -import com.codahale.metrics.Clock; -import com.codahale.metrics.ConsoleReporter; -import com.codahale.metrics.Counter; -import com.codahale.metrics.Gauge; -import com.codahale.metrics.Histogram; -import com.codahale.metrics.Meter; -import com.codahale.metrics.MetricFilter; -import com.codahale.metrics.MetricRegistry; -import com.codahale.metrics.ScheduledReporter; -import com.codahale.metrics.Timer; - - -public class TestReporter extends ScheduledReporter { - - @Getter - private static volatile SortedMap timer = new TreeMap<>(); - - protected TestReporter(MetricRegistry registry, String name, - MetricFilter filter, TimeUnit rateUnit, TimeUnit durationUnit) { - super(registry, name, filter, rateUnit, durationUnit); - - } - - - public static Builder forRegistry(MetricRegistry registry) { - return new Builder(registry); - } - - @Override - public void report(SortedMap gauges, - SortedMap counters, - SortedMap histograms, - SortedMap meters, SortedMap timers) { - this.timer = timers; - - - } - - public static class Builder { - private final MetricRegistry registry; - private PrintStream output; - private Locale locale; - private Clock clock; - private TimeZone timeZone; - private TimeUnit rateUnit; - private TimeUnit durationUnit; - private MetricFilter filter; - - private Builder(MetricRegistry registry) { - this.registry = registry; - this.output = System.out; - this.locale = Locale.getDefault(); - this.clock = Clock.defaultClock(); - this.timeZone = TimeZone.getDefault(); - this.rateUnit = TimeUnit.SECONDS; - this.durationUnit = TimeUnit.MILLISECONDS; - this.filter = MetricFilter.ALL; - } - - /** - * Write to the given {@link PrintStream}. - * - * @param output a {@link PrintStream} instance. - * @return {@code this} - */ - public Builder outputTo(PrintStream output) { - this.output = output; - return this; - } - - /** - * Format numbers for the given {@link Locale}. - * - * @param locale a {@link Locale} - * @return {@code this} - */ - public Builder formattedFor(Locale locale) { - this.locale = locale; - return this; - } - - /** - * Use the given {@link Clock} instance for the time. - * - * @param clock a {@link Clock} instance - * @return {@code this} - */ - public Builder withClock(Clock clock) { - this.clock = clock; - return this; - } - - /** - * Use the given {@link TimeZone} for the time. - * - * @param timeZone a {@link TimeZone} - * @return {@code this} - */ - public Builder formattedFor(TimeZone timeZone) { - this.timeZone = timeZone; - return this; - } - - /** - * Convert rates to the given time unit. - * - * @param rateUnit a unit of time - * @return {@code this} - */ - public Builder convertRatesTo(TimeUnit rateUnit) { - this.rateUnit = rateUnit; - return this; - } - - /** - * Convert durations to the given time unit. - * - * @param durationUnit a unit of time - * @return {@code this} - */ - public Builder convertDurationsTo(TimeUnit durationUnit) { - this.durationUnit = durationUnit; - return this; - } - - /** - * Only report metrics which match the given filter. - * - * @param filter a {@link MetricFilter} - * @return {@code this} - */ - public Builder filter(MetricFilter filter) { - this.filter = filter; - return this; - } - - /** - * Builds a {@link ConsoleReporter} with the given properties. - * - * @return a {@link ConsoleReporter} - */ - public TestReporter build() { - return new TestReporter(registry, - // output, - "name", - // locale, - // clock, - // timeZone, - this.filter, - rateUnit, - durationUnit - ); - } - } - - -} - diff --git a/micro-spring-boot/src/test/java/app/metrics/boot/com/aol/micro/server/TimedResource.java b/micro-spring-boot/src/test/java/app/metrics/boot/com/aol/micro/server/TimedResource.java deleted file mode 100644 index af197479b..000000000 --- a/micro-spring-boot/src/test/java/app/metrics/boot/com/aol/micro/server/TimedResource.java +++ /dev/null @@ -1,17 +0,0 @@ -package app.metrics.boot.com.aol.micro.server; - -import org.springframework.stereotype.Component; - -import com.codahale.metrics.annotation.Timed; -import com.ryantenney.metrics.annotation.Counted; - -@Component -public class TimedResource { - - - @Timed - public String times(){ - - return "ok!"; - } -} diff --git a/micro-spring-boot/src/test/java/app/metrics/boot/com/oath/micro/server/MetricsRunnerTest.java b/micro-spring-boot/src/test/java/app/metrics/boot/com/oath/micro/server/MetricsRunnerTest.java new file mode 100644 index 000000000..cdf358455 --- /dev/null +++ b/micro-spring-boot/src/test/java/app/metrics/boot/com/oath/micro/server/MetricsRunnerTest.java @@ -0,0 +1,56 @@ +package app.metrics.boot.com.oath.micro.server; + + +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + +import java.io.IOException; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; + +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.spring.boot.MicroSpringBoot; +import com.oath.micro.server.spring.metrics.CodahaleMetricsConfigurer; +import com.oath.micro.server.testing.RestAgent; + +@MicroSpringBoot @Microserver +public class MetricsRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer(){ + CodahaleMetricsConfigurer.setInit( metricRegistry -> TestReporter + .forRegistry(metricRegistry) + .build() + .start(10, TimeUnit.MILLISECONDS)); + + server = new MicroserverApp( ()-> "simple-app"); + + + } + + + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException, IOException{ + + + + + + assertThat(rest.get("http://localhost:8080/simple-app/metrics/ping"),is("ok")); + + + assertThat(TestReporter.getTimer().size(),greaterThan(0)); + } + + + +} diff --git a/micro-spring-boot/src/test/java/app/metrics/boot/com/oath/micro/server/MetricsStatusResource.java b/micro-spring-boot/src/test/java/app/metrics/boot/com/oath/micro/server/MetricsStatusResource.java new file mode 100644 index 000000000..c7389afdd --- /dev/null +++ b/micro-spring-boot/src/test/java/app/metrics/boot/com/oath/micro/server/MetricsStatusResource.java @@ -0,0 +1,28 @@ +package app.metrics.boot.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + + + +import com.oath.micro.server.auto.discovery.RestResource; + +@Component +@Path("/metrics") +public class MetricsStatusResource implements RestResource { + + @Autowired + TimedResource timed; + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + timed.times(); + return "ok"; + } + +} \ No newline at end of file diff --git a/micro-spring-boot/src/test/java/app/metrics/boot/com/oath/micro/server/TestReporter.java b/micro-spring-boot/src/test/java/app/metrics/boot/com/oath/micro/server/TestReporter.java new file mode 100644 index 000000000..8c69aa2e3 --- /dev/null +++ b/micro-spring-boot/src/test/java/app/metrics/boot/com/oath/micro/server/TestReporter.java @@ -0,0 +1,169 @@ +package app.metrics.boot.com.oath.micro.server; + +import java.io.PrintStream; +import java.util.Locale; +import java.util.SortedMap; +import java.util.TimeZone; +import java.util.TreeMap; +import java.util.concurrent.TimeUnit; + +import lombok.Getter; + +import com.codahale.metrics.Clock; +import com.codahale.metrics.ConsoleReporter; +import com.codahale.metrics.Counter; +import com.codahale.metrics.Gauge; +import com.codahale.metrics.Histogram; +import com.codahale.metrics.Meter; +import com.codahale.metrics.MetricFilter; +import com.codahale.metrics.MetricRegistry; +import com.codahale.metrics.ScheduledReporter; +import com.codahale.metrics.Timer; + + +public class TestReporter extends ScheduledReporter { + + @Getter + private static volatile SortedMap timer = new TreeMap<>(); + + protected TestReporter(MetricRegistry registry, String name, + MetricFilter filter, TimeUnit rateUnit, TimeUnit durationUnit) { + super(registry, name, filter, rateUnit, durationUnit); + + } + + + public static Builder forRegistry(MetricRegistry registry) { + return new Builder(registry); + } + + @Override + public void report(SortedMap gauges, + SortedMap counters, + SortedMap histograms, + SortedMap meters, SortedMap timers) { + this.timer = timers; + + + } + + public static class Builder { + private final MetricRegistry registry; + private PrintStream output; + private Locale locale; + private Clock clock; + private TimeZone timeZone; + private TimeUnit rateUnit; + private TimeUnit durationUnit; + private MetricFilter filter; + + private Builder(MetricRegistry registry) { + this.registry = registry; + this.output = System.out; + this.locale = Locale.getDefault(); + this.clock = Clock.defaultClock(); + this.timeZone = TimeZone.getDefault(); + this.rateUnit = TimeUnit.SECONDS; + this.durationUnit = TimeUnit.MILLISECONDS; + this.filter = MetricFilter.ALL; + } + + /** + * Write to the given {@link PrintStream}. + * + * @param output a {@link PrintStream} instance. + * @return {@code this} + */ + public Builder outputTo(PrintStream output) { + this.output = output; + return this; + } + + /** + * Format numbers for the given {@link Locale}. + * + * @param locale a {@link Locale} + * @return {@code this} + */ + public Builder formattedFor(Locale locale) { + this.locale = locale; + return this; + } + + /** + * Use the given {@link Clock} instance for the time. + * + * @param clock a {@link Clock} instance + * @return {@code this} + */ + public Builder withClock(Clock clock) { + this.clock = clock; + return this; + } + + /** + * Use the given {@link TimeZone} for the time. + * + * @param timeZone a {@link TimeZone} + * @return {@code this} + */ + public Builder formattedFor(TimeZone timeZone) { + this.timeZone = timeZone; + return this; + } + + /** + * Convert rates to the given time unit. + * + * @param rateUnit a unit of time + * @return {@code this} + */ + public Builder convertRatesTo(TimeUnit rateUnit) { + this.rateUnit = rateUnit; + return this; + } + + /** + * Convert durations to the given time unit. + * + * @param durationUnit a unit of time + * @return {@code this} + */ + public Builder convertDurationsTo(TimeUnit durationUnit) { + this.durationUnit = durationUnit; + return this; + } + + /** + * Only report metrics which match the given filter. + * + * @param filter a {@link MetricFilter} + * @return {@code this} + */ + public Builder filter(MetricFilter filter) { + this.filter = filter; + return this; + } + + /** + * Builds a {@link ConsoleReporter} with the given properties. + * + * @return a {@link ConsoleReporter} + */ + public TestReporter build() { + return new TestReporter(registry, + // output, + "name", + // locale, + // clock, + // timeZone, + this.filter, + rateUnit, + durationUnit + ); + } + } + + +} + diff --git a/micro-spring-boot/src/test/java/app/metrics/boot/com/oath/micro/server/TimedResource.java b/micro-spring-boot/src/test/java/app/metrics/boot/com/oath/micro/server/TimedResource.java new file mode 100644 index 000000000..efafe3099 --- /dev/null +++ b/micro-spring-boot/src/test/java/app/metrics/boot/com/oath/micro/server/TimedResource.java @@ -0,0 +1,16 @@ +package app.metrics.boot.com.oath.micro.server; + +import org.springframework.stereotype.Component; + +import com.codahale.metrics.annotation.Timed; + +@Component +public class TimedResource { + + + @Timed + public String times(){ + + return "ok!"; + } +} diff --git a/micro-spring-boot/src/test/java/app/minimal/com/aol/micro/server/MinimalClassTest.java b/micro-spring-boot/src/test/java/app/minimal/com/aol/micro/server/MinimalClassTest.java deleted file mode 100644 index 14a9344b0..000000000 --- a/micro-spring-boot/src/test/java/app/minimal/com/aol/micro/server/MinimalClassTest.java +++ /dev/null @@ -1,56 +0,0 @@ -package app.minimal.com.aol.micro.server; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.testing.RestAgent; -import com.aol.micro.server.spring.boot.MicroSpringBoot; - -@Rest -@Path("/single") @MicroSpringBoot -public class MinimalClassTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer(){ - - server = new MicroserverApp(()-> "minimal-app"); - - - } - - - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - - - assertThat(rest.get("http://localhost:8080/minimal-app/single/ping"),is("ok1")); - - } - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "ok1"; - } - - -} \ No newline at end of file diff --git a/micro-spring-boot/src/test/java/app/minimal/com/oath/micro/server/MinimalClassTest.java b/micro-spring-boot/src/test/java/app/minimal/com/oath/micro/server/MinimalClassTest.java new file mode 100644 index 000000000..d56c2bf2b --- /dev/null +++ b/micro-spring-boot/src/test/java/app/minimal/com/oath/micro/server/MinimalClassTest.java @@ -0,0 +1,54 @@ +package app.minimal.com.oath.micro.server; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.auto.discovery.Rest; +import com.oath.micro.server.testing.RestAgent; +import com.oath.micro.server.spring.boot.MicroSpringBoot; + +@Rest +@Path("/single") @MicroSpringBoot +public class MinimalClassTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer(){ + + server = new MicroserverApp(()-> "minimal-app"); + + + } + + + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + + + assertThat(rest.get("http://localhost:8080/minimal-app/single/ping"),is("ok1")); + + } + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "ok1"; + } + + +} \ No newline at end of file diff --git a/micro-spring-boot/src/test/java/app/rest/client/com/aol/micro/server/GenericRestClientResource.java b/micro-spring-boot/src/test/java/app/rest/client/com/aol/micro/server/GenericRestClientResource.java deleted file mode 100644 index 8aa6fdec9..000000000 --- a/micro-spring-boot/src/test/java/app/rest/client/com/aol/micro/server/GenericRestClientResource.java +++ /dev/null @@ -1,56 +0,0 @@ -package app.rest.client.com.aol.micro.server; - -import java.util.List; - -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.RestResource; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; - -@Component -@Path("/rest") -public class GenericRestClientResource implements RestResource { - - - @GET - @Produces("application/json") - @Path("/get") - public List get() { - - return ImmutableList.of("ok"); - } - - @POST - @Produces("application/json") - @Path("/post") - public ImmutableSet post(ImmutableMap map) { - - return ImmutableSet.copyOf(map.values()); - } - - @PUT - @Produces("application/json") - @Path("/put") - public ImmutableSet put(ImmutableMap map) { - - return ImmutableSet.copyOf(map.values()); - } - @DELETE - @Produces("application/json") - @Path("/delete") - public List delete(ImmutableMap map) { - - return ImmutableList.of("ok"); - } - - -} \ No newline at end of file diff --git a/micro-spring-boot/src/test/java/app/rest/client/com/aol/micro/server/MyEntity.java b/micro-spring-boot/src/test/java/app/rest/client/com/aol/micro/server/MyEntity.java deleted file mode 100644 index 1d2fa9b71..000000000 --- a/micro-spring-boot/src/test/java/app/rest/client/com/aol/micro/server/MyEntity.java +++ /dev/null @@ -1,12 +0,0 @@ -package app.rest.client.com.aol.micro.server; - -import lombok.EqualsAndHashCode; -import lombok.Getter; - -@EqualsAndHashCode -@Getter -public class MyEntity { - - private final String name ="myEntity"; - -} diff --git a/micro-spring-boot/src/test/java/app/rest/client/com/aol/micro/server/RestClientResource.java b/micro-spring-boot/src/test/java/app/rest/client/com/aol/micro/server/RestClientResource.java deleted file mode 100644 index c784b47d7..000000000 --- a/micro-spring-boot/src/test/java/app/rest/client/com/aol/micro/server/RestClientResource.java +++ /dev/null @@ -1,54 +0,0 @@ -package app.rest.client.com.aol.micro.server; - -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.RestResource; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; - -@Component -@Path("/generics") -public class RestClientResource implements RestResource { - - private final ImmutableList result = ImmutableList.of(new MyEntity()); - @GET - @Produces("application/json") - @Path("/get") - public ImmutableList get() { - - return result; - } - - @POST - @Produces("application/json") - @Path("/post") - public ImmutableList post(ImmutableMap map) { - - return result; - } - - @PUT - @Produces("application/json") - @Path("/put") - public ImmutableList put(ImmutableMap map) { - - return result; - } - @DELETE - @Produces("application/json") - @Path("/delete") - public ImmutableList delete(ImmutableMap map) { - - return result; - } - - -} \ No newline at end of file diff --git a/micro-spring-boot/src/test/java/app/rest/client/com/aol/micro/server/RestClientTest.java b/micro-spring-boot/src/test/java/app/rest/client/com/aol/micro/server/RestClientTest.java deleted file mode 100644 index 9f1c86922..000000000 --- a/micro-spring-boot/src/test/java/app/rest/client/com/aol/micro/server/RestClientTest.java +++ /dev/null @@ -1,116 +0,0 @@ - -package app.rest.client.com.aol.micro.server; - - -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.assertThat; - -import java.net.URI; -import java.net.URISyntaxException; -import java.util.List; -import java.util.concurrent.ExecutionException; - -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.springframework.core.ParameterizedTypeReference; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpMethod; -import org.springframework.web.client.RestClientException; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.rest.client.nio.AsyncRestClient; -import com.aol.micro.server.rest.client.nio.NIORestClient; -import com.aol.micro.server.rest.client.nio.SpringConfig; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.aol.micro.server.spring.boot.MicroSpringBoot; - -@Microserver @MicroSpringBoot -public class RestClientTest { - - private final AsyncRestClient> listClient = new AsyncRestClient(1000,1000).withResponse(List.class); - private final AsyncRestClient> setClient = new AsyncRestClient(1000,1000).withResponse(ImmutableSet.class);; - private final AsyncRestClient> genericsClient = new AsyncRestClient(1000,1000).withGenericResponse(ImmutableList.class, MyEntity.class); - - private final NIORestClient rest = new SpringConfig().restClient(); - - - MicroserverApp server; - static volatile boolean run = false; - @Before - public void startServer(){ - if(run) - return; - run = true; - server = new MicroserverApp( RestClientTest.class, ()-> "rest-app"); - - - } - - - /* - * Simpler with JaxRsNIOClient - */ - @Test - public void testCRUD() throws InterruptedException, ExecutionException{ - - - assertThat(listClient.get("http://localhost:8080/rest-app/rest/get").get().get(0),is("ok")); - assertThat(setClient.post("http://localhost:8080/rest-app/rest/post",ImmutableMap.of(1,"hello")).get(),is(ImmutableSet.of("hello"))); - assertThat(setClient.put("http://localhost:8080/rest-app/rest/put",ImmutableMap.of(1,"hello")).get(),is(ImmutableSet.of("hello"))); - assertThat(listClient.delete("http://localhost:8080/rest-app/rest/delete").get().get(0),is("ok")); - } - - @Test - public void testCRUDGenerics() throws InterruptedException, ExecutionException{ - - - assertThat(genericsClient.get("http://localhost:8080/rest-app/generics/get").get().get(0),is(new MyEntity())); - assertThat(genericsClient.post("http://localhost:8080/rest-app/generics/post",ImmutableMap.of(1,"hello")).get(),is(ImmutableList.of(new MyEntity()))); - assertThat(genericsClient.put("http://localhost:8080/rest-app/generics/put",ImmutableMap.of(1,"hello")).get(),is(ImmutableList.of(new MyEntity()))); - assertThat(genericsClient.delete("http://localhost:8080/rest-app/generics/delete").get().get(0),is(new MyEntity())); - } - - /** - * More complex with Spring REST Template Based NIORestTemplate - * - */ - - @Test - public void testCRUDSpring() throws InterruptedException, ExecutionException, RestClientException, URISyntaxException{ - - - assertThat(rest.getForEntity(new URI("http://localhost:8080/rest-app/rest/get"),List.class).get().getBody().get(0),is("ok")); - - assertThat(rest.postForEntity("http://localhost:8080/rest-app/rest/post", new HttpEntity(ImmutableMap.of(1,"hello")), ImmutableSet.class).get().getBody(),is(ImmutableSet.of("hello"))); - assertThat( rest.put("http://localhost:8080/rest-app/rest/put",new HttpEntity(ImmutableMap.of(1,"hello")),ImmutableSet.class).get() - ,is(nullValue())); - assertThat(rest.delete("http://localhost:8080/rest-app/rest/delete").get(),is(nullValue())); - } - - @Test - public void testCRUDGenericsSpring() throws InterruptedException, ExecutionException{ - - - assertThat(rest.exchange("http://localhost:8080/rest-app/generics/get",HttpMethod.GET,null,new ParameterizedTypeReference>(){}) - .get().getBody().get(0),is(new MyEntity())); - - assertThat(rest.exchange("http://localhost:8080/rest-app/generics/post",HttpMethod.POST,new HttpEntity(ImmutableMap.of(1,"hello")),new ParameterizedTypeReference>(){}) - .get().getBody(),is(ImmutableList.of(new MyEntity()))); - - assertThat(rest.exchange("http://localhost:8080/rest-app/generics/put",HttpMethod.PUT,new HttpEntity(ImmutableMap.of(1,"hello")),new ParameterizedTypeReference>(){}) - .get().getBody(),is(ImmutableList.of(new MyEntity()))); - - assertThat(rest.exchange("http://localhost:8080/rest-app/generics/delete",HttpMethod.DELETE,null,new ParameterizedTypeReference>(){}) - .get().getBody().get(0),is(new MyEntity())); - - } - - - -} diff --git a/micro-spring-boot/src/test/java/app/rest/client/com/oath/micro/server/GenericRestClientResource.java b/micro-spring-boot/src/test/java/app/rest/client/com/oath/micro/server/GenericRestClientResource.java new file mode 100644 index 000000000..3b6b9ee90 --- /dev/null +++ b/micro-spring-boot/src/test/java/app/rest/client/com/oath/micro/server/GenericRestClientResource.java @@ -0,0 +1,56 @@ +package app.rest.client.com.oath.micro.server; + +import java.util.List; + +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.RestResource; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; + +@Component +@Path("/rest") +public class GenericRestClientResource implements RestResource { + + + @GET + @Produces("application/json") + @Path("/get") + public List get() { + + return ImmutableList.of("ok"); + } + + @POST + @Produces("application/json") + @Path("/post") + public ImmutableSet post(ImmutableMap map) { + + return ImmutableSet.copyOf(map.values()); + } + + @PUT + @Produces("application/json") + @Path("/put") + public ImmutableSet put(ImmutableMap map) { + + return ImmutableSet.copyOf(map.values()); + } + @DELETE + @Produces("application/json") + @Path("/delete") + public List delete(ImmutableMap map) { + + return ImmutableList.of("ok"); + } + + +} \ No newline at end of file diff --git a/micro-spring-boot/src/test/java/app/rest/client/com/oath/micro/server/MyEntity.java b/micro-spring-boot/src/test/java/app/rest/client/com/oath/micro/server/MyEntity.java new file mode 100644 index 000000000..c075fa67f --- /dev/null +++ b/micro-spring-boot/src/test/java/app/rest/client/com/oath/micro/server/MyEntity.java @@ -0,0 +1,12 @@ +package app.rest.client.com.oath.micro.server; + +import lombok.EqualsAndHashCode; +import lombok.Getter; + +@EqualsAndHashCode +@Getter +public class MyEntity { + + private final String name ="myEntity"; + +} diff --git a/micro-spring-boot/src/test/java/app/rest/client/com/oath/micro/server/RestClientResource.java b/micro-spring-boot/src/test/java/app/rest/client/com/oath/micro/server/RestClientResource.java new file mode 100644 index 000000000..90c119ba5 --- /dev/null +++ b/micro-spring-boot/src/test/java/app/rest/client/com/oath/micro/server/RestClientResource.java @@ -0,0 +1,53 @@ +package app.rest.client.com.oath.micro.server; + +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.RestResource; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; + +@Component +@Path("/generics") +public class RestClientResource implements RestResource { + + private final ImmutableList result = ImmutableList.of(new MyEntity()); + @GET + @Produces("application/json") + @Path("/get") + public ImmutableList get() { + + return result; + } + + @POST + @Produces("application/json") + @Path("/post") + public ImmutableList post(ImmutableMap map) { + + return result; + } + + @PUT + @Produces("application/json") + @Path("/put") + public ImmutableList put(ImmutableMap map) { + + return result; + } + @DELETE + @Produces("application/json") + @Path("/delete") + public ImmutableList delete(ImmutableMap map) { + + return result; + } + + +} \ No newline at end of file diff --git a/micro-spring-boot/src/test/java/app/rest/client/com/oath/micro/server/RestClientTest.java b/micro-spring-boot/src/test/java/app/rest/client/com/oath/micro/server/RestClientTest.java new file mode 100644 index 000000000..593e23fa4 --- /dev/null +++ b/micro-spring-boot/src/test/java/app/rest/client/com/oath/micro/server/RestClientTest.java @@ -0,0 +1,114 @@ + +package app.rest.client.com.oath.micro.server; + + +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.assertThat; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.List; +import java.util.concurrent.ExecutionException; + +import org.junit.Before; +import org.junit.Test; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpMethod; +import org.springframework.web.client.RestClientException; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.rest.client.nio.AsyncRestClient; +import com.oath.micro.server.rest.client.nio.NIORestClient; +import com.oath.micro.server.rest.client.nio.SpringConfig; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.oath.micro.server.spring.boot.MicroSpringBoot; + +@Microserver @MicroSpringBoot +public class RestClientTest { + + private final AsyncRestClient> listClient = new AsyncRestClient(1000,1000).withResponse(List.class); + private final AsyncRestClient> setClient = new AsyncRestClient(1000,1000).withResponse(ImmutableSet.class);; + private final AsyncRestClient> genericsClient = new AsyncRestClient(1000,1000).withGenericResponse(ImmutableList.class, MyEntity.class); + + private final NIORestClient rest = new SpringConfig().restClient(); + + + MicroserverApp server; + static volatile boolean run = false; + @Before + public void startServer(){ + if(run) + return; + run = true; + server = new MicroserverApp( RestClientTest.class, ()-> "rest-app"); + + + } + + + /* + * Simpler with JaxRsNIOClient + */ + @Test + public void testCRUD() throws InterruptedException, ExecutionException{ + + + assertThat(listClient.get("http://localhost:8080/rest-app/rest/get").get().get(0),is("ok")); + assertThat(setClient.post("http://localhost:8080/rest-app/rest/post",ImmutableMap.of(1,"hello")).get(),is(ImmutableSet.of("hello"))); + assertThat(setClient.put("http://localhost:8080/rest-app/rest/put",ImmutableMap.of(1,"hello")).get(),is(ImmutableSet.of("hello"))); + assertThat(listClient.delete("http://localhost:8080/rest-app/rest/delete").get().get(0),is("ok")); + } + + @Test + public void testCRUDGenerics() throws InterruptedException, ExecutionException{ + + + assertThat(genericsClient.get("http://localhost:8080/rest-app/generics/get").get().get(0),is(new MyEntity())); + assertThat(genericsClient.post("http://localhost:8080/rest-app/generics/post",ImmutableMap.of(1,"hello")).get(),is(ImmutableList.of(new MyEntity()))); + assertThat(genericsClient.put("http://localhost:8080/rest-app/generics/put",ImmutableMap.of(1,"hello")).get(),is(ImmutableList.of(new MyEntity()))); + assertThat(genericsClient.delete("http://localhost:8080/rest-app/generics/delete").get().get(0),is(new MyEntity())); + } + + /** + * More complex with Spring REST Template Based NIORestTemplate + * + */ + + @Test + public void testCRUDSpring() throws InterruptedException, ExecutionException, RestClientException, URISyntaxException{ + + + assertThat(rest.getForEntity(new URI("http://localhost:8080/rest-app/rest/get"),List.class).get().getBody().get(0),is("ok")); + + assertThat(rest.postForEntity("http://localhost:8080/rest-app/rest/post", new HttpEntity(ImmutableMap.of(1,"hello")), ImmutableSet.class).get().getBody(),is(ImmutableSet.of("hello"))); + assertThat( rest.put("http://localhost:8080/rest-app/rest/put",new HttpEntity(ImmutableMap.of(1,"hello")),ImmutableSet.class).get() + ,is(nullValue())); + assertThat(rest.delete("http://localhost:8080/rest-app/rest/delete").get(),is(nullValue())); + } + + @Test + public void testCRUDGenericsSpring() throws InterruptedException, ExecutionException{ + + + assertThat(rest.exchange("http://localhost:8080/rest-app/generics/get",HttpMethod.GET,null,new ParameterizedTypeReference>(){}) + .get().getBody().get(0),is(new MyEntity())); + + assertThat(rest.exchange("http://localhost:8080/rest-app/generics/post",HttpMethod.POST,new HttpEntity(ImmutableMap.of(1,"hello")),new ParameterizedTypeReference>(){}) + .get().getBody(),is(ImmutableList.of(new MyEntity()))); + + assertThat(rest.exchange("http://localhost:8080/rest-app/generics/put",HttpMethod.PUT,new HttpEntity(ImmutableMap.of(1,"hello")),new ParameterizedTypeReference>(){}) + .get().getBody(),is(ImmutableList.of(new MyEntity()))); + + assertThat(rest.exchange("http://localhost:8080/rest-app/generics/delete",HttpMethod.DELETE,null,new ParameterizedTypeReference>(){}) + .get().getBody().get(0),is(new MyEntity())); + + } + + + +} diff --git a/micro-spring-boot/src/test/java/app/simple/com/aol/micro/server/SimpleRunnerTest.java b/micro-spring-boot/src/test/java/app/simple/com/aol/micro/server/SimpleRunnerTest.java deleted file mode 100644 index af811647d..000000000 --- a/micro-spring-boot/src/test/java/app/simple/com/aol/micro/server/SimpleRunnerTest.java +++ /dev/null @@ -1,48 +0,0 @@ -package app.simple.com.aol.micro.server; - - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.spring.boot.MicroSpringBoot; -import com.aol.micro.server.testing.RestAgent; -import com.aol.micro.server.spring.boot.MicroSpringBoot; - -@Microserver @MicroSpringBoot -public class SimpleRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer(){ - - server = new MicroserverApp( SimpleRunnerTest.class, ()-> "simple-app"); - - - } - - - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - - - assertThat(rest.get("http://localhost:8080/simple-app/status/ping"),is("ok")); - - - } - - - -} diff --git a/micro-spring-boot/src/test/java/app/simple/com/aol/micro/server/SimpleStatusResource.java b/micro-spring-boot/src/test/java/app/simple/com/aol/micro/server/SimpleStatusResource.java deleted file mode 100644 index 0093fe138..000000000 --- a/micro-spring-boot/src/test/java/app/simple/com/aol/micro/server/SimpleStatusResource.java +++ /dev/null @@ -1,28 +0,0 @@ -package app.simple.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.RestResource; - -@Component -@Qualifier("simpleStatusResource") -@Path("/status") -public class SimpleStatusResource implements RestResource { - - - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - - return "ok"; - } - - -} \ No newline at end of file diff --git a/micro-spring-boot/src/test/java/app/simple/com/oath/micro/server/SimpleRunnerTest.java b/micro-spring-boot/src/test/java/app/simple/com/oath/micro/server/SimpleRunnerTest.java new file mode 100644 index 000000000..97f8871f1 --- /dev/null +++ b/micro-spring-boot/src/test/java/app/simple/com/oath/micro/server/SimpleRunnerTest.java @@ -0,0 +1,45 @@ +package app.simple.com.oath.micro.server; + + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.spring.boot.MicroSpringBoot; +import com.oath.micro.server.testing.RestAgent; + +@Microserver @MicroSpringBoot +public class SimpleRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer(){ + + server = new MicroserverApp( SimpleRunnerTest.class, ()-> "simple-app"); + + + } + + + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + + + assertThat(rest.get("http://localhost:8080/simple-app/status/ping"),is("ok")); + + + } + + + +} diff --git a/micro-spring-boot/src/test/java/app/simple/com/oath/micro/server/SimpleStatusResource.java b/micro-spring-boot/src/test/java/app/simple/com/oath/micro/server/SimpleStatusResource.java new file mode 100644 index 000000000..97265ed02 --- /dev/null +++ b/micro-spring-boot/src/test/java/app/simple/com/oath/micro/server/SimpleStatusResource.java @@ -0,0 +1,28 @@ +package app.simple.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.RestResource; + +@Component +@Qualifier("simpleStatusResource") +@Path("/status") +public class SimpleStatusResource implements RestResource { + + + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + + return "ok"; + } + + +} \ No newline at end of file diff --git a/micro-spring-boot/src/test/java/app/spring/com/aol/micro/server/MyBean.java b/micro-spring-boot/src/test/java/app/spring/com/aol/micro/server/MyBean.java deleted file mode 100644 index 1f7a589ff..000000000 --- a/micro-spring-boot/src/test/java/app/spring/com/aol/micro/server/MyBean.java +++ /dev/null @@ -1,12 +0,0 @@ -package app.spring.com.aol.micro.server; - -import javax.inject.Inject; - -import lombok.Getter; - -@Getter -public class MyBean { - - @Inject - private MyDependency injected; -} diff --git a/micro-spring-boot/src/test/java/app/spring/com/aol/micro/server/MyDependency.java b/micro-spring-boot/src/test/java/app/spring/com/aol/micro/server/MyDependency.java deleted file mode 100644 index 48d89e6c5..000000000 --- a/micro-spring-boot/src/test/java/app/spring/com/aol/micro/server/MyDependency.java +++ /dev/null @@ -1,12 +0,0 @@ -package app.spring.com.aol.micro.server; - -import lombok.Getter; - -import org.springframework.stereotype.Component; - -@Component -@Getter -public class MyDependency { - - private String data = "hello world"; -} diff --git a/micro-spring-boot/src/test/java/app/spring/com/aol/micro/server/SpringRunnerTest.java b/micro-spring-boot/src/test/java/app/spring/com/aol/micro/server/SpringRunnerTest.java deleted file mode 100644 index 4f0b93786..000000000 --- a/micro-spring-boot/src/test/java/app/spring/com/aol/micro/server/SpringRunnerTest.java +++ /dev/null @@ -1,51 +0,0 @@ -package app.spring.com.aol.micro.server; - - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.springframework.context.annotation.Bean; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.spring.boot.MicroSpringBoot; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.testing.RestAgent; - -@Microserver @MicroSpringBoot -public class SpringRunnerTest { - - RestAgent rest = new RestAgent(); - - @Bean - public MyBean mybean(){ - return new MyBean(); - } - - MicroserverApp server; - @Before - public void startServer(){ - - server = new MicroserverApp( SpringRunnerTest.class, ()-> "spring-app"); - - - } - - - @Test - public void testAutoWiring() throws InterruptedException, ExecutionException{ - - assertThat(rest.get("http://localhost:8080/spring-app/spring/ping"),is("hello world")); - - } - - - - - -} diff --git a/micro-spring-boot/src/test/java/app/spring/com/aol/micro/server/SpringStatusResource.java b/micro-spring-boot/src/test/java/app/spring/com/aol/micro/server/SpringStatusResource.java deleted file mode 100644 index 331ac997e..000000000 --- a/micro-spring-boot/src/test/java/app/spring/com/aol/micro/server/SpringStatusResource.java +++ /dev/null @@ -1,32 +0,0 @@ -package app.spring.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.RestResource; - -@Component -@Path("/spring") -public class SpringStatusResource implements RestResource { - - @Autowired - private MyBean mybean; - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return mybean.getInjected().getData(); - } - @GET - @Produces("text/plain") - @Path("/ping2") - public String ping2() { - return "ok"; - } - -} \ No newline at end of file diff --git a/micro-spring-boot/src/test/java/app/spring/com/oath/micro/server/MyBean.java b/micro-spring-boot/src/test/java/app/spring/com/oath/micro/server/MyBean.java new file mode 100644 index 000000000..328b7d185 --- /dev/null +++ b/micro-spring-boot/src/test/java/app/spring/com/oath/micro/server/MyBean.java @@ -0,0 +1,12 @@ +package app.spring.com.oath.micro.server; + +import javax.inject.Inject; + +import lombok.Getter; + +@Getter +public class MyBean { + + @Inject + private MyDependency injected; +} diff --git a/micro-spring-boot/src/test/java/app/spring/com/oath/micro/server/MyDependency.java b/micro-spring-boot/src/test/java/app/spring/com/oath/micro/server/MyDependency.java new file mode 100644 index 000000000..1ca23b15b --- /dev/null +++ b/micro-spring-boot/src/test/java/app/spring/com/oath/micro/server/MyDependency.java @@ -0,0 +1,12 @@ +package app.spring.com.oath.micro.server; + +import lombok.Getter; + +import org.springframework.stereotype.Component; + +@Component +@Getter +public class MyDependency { + + private String data = "hello world"; +} diff --git a/micro-spring-boot/src/test/java/app/spring/com/oath/micro/server/SpringRunnerTest.java b/micro-spring-boot/src/test/java/app/spring/com/oath/micro/server/SpringRunnerTest.java new file mode 100644 index 000000000..3f114b966 --- /dev/null +++ b/micro-spring-boot/src/test/java/app/spring/com/oath/micro/server/SpringRunnerTest.java @@ -0,0 +1,49 @@ +package app.spring.com.oath.micro.server; + + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import org.junit.Before; +import org.junit.Test; +import org.springframework.context.annotation.Bean; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.spring.boot.MicroSpringBoot; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.testing.RestAgent; + +@Microserver @MicroSpringBoot +public class SpringRunnerTest { + + RestAgent rest = new RestAgent(); + + @Bean + public MyBean mybean(){ + return new MyBean(); + } + + MicroserverApp server; + @Before + public void startServer(){ + + server = new MicroserverApp( SpringRunnerTest.class, ()-> "spring-app"); + + + } + + + @Test + public void testAutoWiring() throws InterruptedException, ExecutionException{ + + assertThat(rest.get("http://localhost:8080/spring-app/spring/ping"),is("hello world")); + + } + + + + + +} diff --git a/micro-spring-boot/src/test/java/app/spring/com/oath/micro/server/SpringStatusResource.java b/micro-spring-boot/src/test/java/app/spring/com/oath/micro/server/SpringStatusResource.java new file mode 100644 index 000000000..ae0c817de --- /dev/null +++ b/micro-spring-boot/src/test/java/app/spring/com/oath/micro/server/SpringStatusResource.java @@ -0,0 +1,32 @@ +package app.spring.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.RestResource; + +@Component +@Path("/spring") +public class SpringStatusResource implements RestResource { + + @Autowired + private MyBean mybean; + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return mybean.getInjected().getData(); + } + @GET + @Produces("text/plain") + @Path("/ping2") + public String ping2() { + return "ok"; + } + +} \ No newline at end of file diff --git a/micro-spring-boot/src/test/java/app/swagger/com/aol/micro/server/StatsResource.java b/micro-spring-boot/src/test/java/app/swagger/com/aol/micro/server/StatsResource.java deleted file mode 100644 index 3d3516a41..000000000 --- a/micro-spring-boot/src/test/java/app/swagger/com/aol/micro/server/StatsResource.java +++ /dev/null @@ -1,31 +0,0 @@ -package app.swagger.com.aol.micro.server; - -import java.util.List; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.RestResource; -import com.google.common.collect.ImmutableList; -import com.wordnik.swagger.annotations.Api; -import com.wordnik.swagger.annotations.ApiOperation; - - -@Path("/stats") -@Component -@Api(value = "/stats", description = "Resource to show stats for a box using sigar") -public class StatsResource implements RestResource { - - - - @GET - @Path("/ping") - @Produces("application/json") - @ApiOperation(value = "Make a ping call", response = List.class) - public List getMachineStats() { - return ImmutableList.of(1); - } -} diff --git a/micro-spring-boot/src/test/java/app/swagger/com/aol/micro/server/SwaggerRunnerTest.java b/micro-spring-boot/src/test/java/app/swagger/com/aol/micro/server/SwaggerRunnerTest.java deleted file mode 100644 index 80eb62942..000000000 --- a/micro-spring-boot/src/test/java/app/swagger/com/aol/micro/server/SwaggerRunnerTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package app.swagger.com.aol.micro.server; - -import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.testing.RestAgent; -import com.aol.micro.server.module.Module; -import com.aol.micro.server.spring.boot.MicroSpringBoot; - -@Configuration -@ComponentScan(basePackages = { "app.swagger.com.aol.micro.server" }) -@MicroSpringBoot // needs some work for spring-boot -public class SwaggerRunnerTest implements Module{ - - - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer(){ - - server = new MicroserverApp( SwaggerRunnerTest.class,this); - - - } - - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - - - assertThat(rest.getJson("http://localhost:8080/swagger-app/stats/ping"),containsString("1")); - assertThat(rest.getJson("http://localhost:8080/swagger-app/api-docs"),containsString("apiVersion")); - - } - - - @Override - public String getContext() { - return "swagger-app"; - } - - - -} diff --git a/micro-spring-boot/src/test/java/app/swagger/com/oath/micro/server/StatsResource.java b/micro-spring-boot/src/test/java/app/swagger/com/oath/micro/server/StatsResource.java new file mode 100644 index 000000000..848d10205 --- /dev/null +++ b/micro-spring-boot/src/test/java/app/swagger/com/oath/micro/server/StatsResource.java @@ -0,0 +1,31 @@ +package app.swagger.com.oath.micro.server; + +import java.util.List; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.RestResource; +import com.google.common.collect.ImmutableList; +import com.wordnik.swagger.annotations.Api; +import com.wordnik.swagger.annotations.ApiOperation; + + +@Path("/stats") +@Component +@Api(value = "/stats", description = "Resource to show stats for a box using sigar") +public class StatsResource implements RestResource { + + + + @GET + @Path("/ping") + @Produces("application/json") + @ApiOperation(value = "Make a ping call", response = List.class) + public List getMachineStats() { + return ImmutableList.of(1); + } +} diff --git a/micro-spring-boot/src/test/java/app/swagger/com/oath/micro/server/SwaggerRunnerTest.java b/micro-spring-boot/src/test/java/app/swagger/com/oath/micro/server/SwaggerRunnerTest.java new file mode 100644 index 000000000..07f6382b1 --- /dev/null +++ b/micro-spring-boot/src/test/java/app/swagger/com/oath/micro/server/SwaggerRunnerTest.java @@ -0,0 +1,55 @@ +package app.swagger.com.oath.micro.server; + +import static org.hamcrest.Matchers.containsString; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import org.junit.Before; +import org.junit.Test; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.testing.RestAgent; +import com.oath.micro.server.module.Module; +import com.oath.micro.server.spring.boot.MicroSpringBoot; + +@Configuration +@ComponentScan(basePackages = { "app.swagger.com.oath.micro.server" }) +@MicroSpringBoot // needs some work for spring-boot +public class SwaggerRunnerTest implements Module{ + + + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer(){ + + server = new MicroserverApp( SwaggerRunnerTest.class,this); + + + } + + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + + + assertThat(rest.getJson("http://localhost:8080/swagger-app/stats/ping"),containsString("1")); + assertThat(rest.getJson("http://localhost:8080/swagger-app/api-docs"),containsString("apiVersion")); + + } + + + @Override + public String getContext() { + return "swagger-app"; + } + + + +} diff --git a/micro-spring-boot/src/test/java/com/aol/micro/server/testing/RestAgent.java b/micro-spring-boot/src/test/java/com/aol/micro/server/testing/RestAgent.java deleted file mode 100644 index ce204f810..000000000 --- a/micro-spring-boot/src/test/java/com/aol/micro/server/testing/RestAgent.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.aol.micro.server.testing; - -import java.util.List; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.Invocation.Builder; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; - -import com.aol.micro.server.rest.jackson.JacksonUtil; - -public class RestAgent { - - - public String getJson(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.get(String.class); - - } - - public String get(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.TEXT_PLAIN); - - return request.get(String.class); - - } - - public T post(String url, Object payload,Class type) { - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); - } - - -} diff --git a/micro-spring-boot/src/test/java/com/oath/micro/server/testing/RestAgent.java b/micro-spring-boot/src/test/java/com/oath/micro/server/testing/RestAgent.java new file mode 100644 index 000000000..b2b86303e --- /dev/null +++ b/micro-spring-boot/src/test/java/com/oath/micro/server/testing/RestAgent.java @@ -0,0 +1,53 @@ +package com.oath.micro.server.testing; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.Invocation.Builder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; + +import com.oath.micro.server.rest.jackson.JacksonUtil; + +public class RestAgent { + + + public String getJson(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.get(String.class); + + } + + public String get(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.TEXT_PLAIN); + + return request.get(String.class); + + } + + public T post(String url, Object payload,Class type) { + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); + } + + +} diff --git a/micro-swagger/src/main/java/com/aol/micro/server/rest/swagger/SwaggerInitializer.java b/micro-swagger/src/main/java/com/oath/micro/server/rest/swagger/SwaggerInitializer.java similarity index 84% rename from micro-swagger/src/main/java/com/aol/micro/server/rest/swagger/SwaggerInitializer.java rename to micro-swagger/src/main/java/com/oath/micro/server/rest/swagger/SwaggerInitializer.java index 134ed37e4..62d17f85e 100644 --- a/micro-swagger/src/main/java/com/aol/micro/server/rest/swagger/SwaggerInitializer.java +++ b/micro-swagger/src/main/java/com/oath/micro/server/rest/swagger/SwaggerInitializer.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.rest.swagger; +package com.oath.micro.server.rest.swagger; import java.util.stream.Collectors; @@ -7,15 +7,10 @@ import javax.servlet.ServletContextListener; import javax.ws.rs.core.Application; -import lombok.Setter; - -import org.springframework.beans.factory.annotation.Autowired; - import scala.collection.JavaConversions; import scala.collection.immutable.List; -import com.aol.micro.server.auto.discovery.RestResource; -import com.aol.micro.server.servers.model.ServerData; +import com.oath.micro.server.servers.model.ServerData; import com.wordnik.swagger.jaxrs.config.BeanConfig; public class SwaggerInitializer implements ServletContextListener { diff --git a/micro-swagger/src/main/java/com/aol/micro/server/rest/swagger/SwaggerPlugin.java b/micro-swagger/src/main/java/com/oath/micro/server/rest/swagger/SwaggerPlugin.java similarity index 84% rename from micro-swagger/src/main/java/com/aol/micro/server/rest/swagger/SwaggerPlugin.java rename to micro-swagger/src/main/java/com/oath/micro/server/rest/swagger/SwaggerPlugin.java index 118a1104b..bec20a382 100644 --- a/micro-swagger/src/main/java/com/aol/micro/server/rest/swagger/SwaggerPlugin.java +++ b/micro-swagger/src/main/java/com/oath/micro/server/rest/swagger/SwaggerPlugin.java @@ -1,19 +1,16 @@ -package com.aol.micro.server.rest.swagger; +package com.oath.micro.server.rest.swagger; -import java.util.Arrays; -import java.util.HashSet; import java.util.Set; import java.util.function.Function; import javax.servlet.ServletContextListener; -import com.aol.micro.server.Plugin; -import com.aol.micro.server.servers.model.ServerData; +import com.oath.micro.server.Plugin; +import com.oath.micro.server.servers.model.ServerData; import com.wordnik.swagger.jaxrs.listing.ApiListingResourceJSON; import com.wordnik.swagger.jersey.listing.JerseyApiDeclarationProvider; import com.wordnik.swagger.jersey.listing.JerseyResourceListingProvider; -import cyclops.collections.immutable.PersistentSetX; import cyclops.collections.mutable.SetX; import cyclops.function.Lambda; diff --git a/micro-swagger/src/main/resources/META-INF/services/com.aol.micro.server.Plugin b/micro-swagger/src/main/resources/META-INF/services/com.aol.micro.server.Plugin deleted file mode 100644 index af043f2d8..000000000 --- a/micro-swagger/src/main/resources/META-INF/services/com.aol.micro.server.Plugin +++ /dev/null @@ -1 +0,0 @@ -com.aol.micro.server.rest.swagger.SwaggerPlugin \ No newline at end of file diff --git a/micro-swagger/src/main/resources/META-INF/services/com.oath.micro.server.Plugin b/micro-swagger/src/main/resources/META-INF/services/com.oath.micro.server.Plugin new file mode 100644 index 000000000..cc13efc43 --- /dev/null +++ b/micro-swagger/src/main/resources/META-INF/services/com.oath.micro.server.Plugin @@ -0,0 +1 @@ +com.oath.micro.server.rest.swagger.SwaggerPlugin \ No newline at end of file diff --git a/micro-swagger/src/test/java/app/swagger/com/aol/micro/server/StatsResource.java b/micro-swagger/src/test/java/app/swagger/com/aol/micro/server/StatsResource.java deleted file mode 100644 index 3d3516a41..000000000 --- a/micro-swagger/src/test/java/app/swagger/com/aol/micro/server/StatsResource.java +++ /dev/null @@ -1,31 +0,0 @@ -package app.swagger.com.aol.micro.server; - -import java.util.List; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.RestResource; -import com.google.common.collect.ImmutableList; -import com.wordnik.swagger.annotations.Api; -import com.wordnik.swagger.annotations.ApiOperation; - - -@Path("/stats") -@Component -@Api(value = "/stats", description = "Resource to show stats for a box using sigar") -public class StatsResource implements RestResource { - - - - @GET - @Path("/ping") - @Produces("application/json") - @ApiOperation(value = "Make a ping call", response = List.class) - public List getMachineStats() { - return ImmutableList.of(1); - } -} diff --git a/micro-swagger/src/test/java/app/swagger/com/aol/micro/server/SwaggerRunnerTest.java b/micro-swagger/src/test/java/app/swagger/com/aol/micro/server/SwaggerRunnerTest.java deleted file mode 100644 index 2f05228b3..000000000 --- a/micro-swagger/src/test/java/app/swagger/com/aol/micro/server/SwaggerRunnerTest.java +++ /dev/null @@ -1,49 +0,0 @@ -package app.swagger.com.aol.micro.server; - -import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.testing.RestAgent; - -@Configuration -@ComponentScan(basePackages = { "app.swagger.com.aol.micro.server" }) -public class SwaggerRunnerTest { - - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer(){ - - server = new MicroserverApp( SwaggerRunnerTest.class, ()-> "swagger-app"); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - - - assertThat(rest.getJson("http://localhost:8080/api-docs/stats"),containsString("Make a ping call")); - - } - - - -} diff --git a/micro-swagger/src/test/java/app/swagger/com/oath/micro/server/StatsResource.java b/micro-swagger/src/test/java/app/swagger/com/oath/micro/server/StatsResource.java new file mode 100644 index 000000000..848d10205 --- /dev/null +++ b/micro-swagger/src/test/java/app/swagger/com/oath/micro/server/StatsResource.java @@ -0,0 +1,31 @@ +package app.swagger.com.oath.micro.server; + +import java.util.List; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.RestResource; +import com.google.common.collect.ImmutableList; +import com.wordnik.swagger.annotations.Api; +import com.wordnik.swagger.annotations.ApiOperation; + + +@Path("/stats") +@Component +@Api(value = "/stats", description = "Resource to show stats for a box using sigar") +public class StatsResource implements RestResource { + + + + @GET + @Path("/ping") + @Produces("application/json") + @ApiOperation(value = "Make a ping call", response = List.class) + public List getMachineStats() { + return ImmutableList.of(1); + } +} diff --git a/micro-swagger/src/test/java/app/swagger/com/oath/micro/server/SwaggerRunnerTest.java b/micro-swagger/src/test/java/app/swagger/com/oath/micro/server/SwaggerRunnerTest.java new file mode 100644 index 000000000..5f9c6351c --- /dev/null +++ b/micro-swagger/src/test/java/app/swagger/com/oath/micro/server/SwaggerRunnerTest.java @@ -0,0 +1,49 @@ +package app.swagger.com.oath.micro.server; + +import static org.hamcrest.Matchers.containsString; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.testing.RestAgent; + +@Configuration +@ComponentScan(basePackages = { "app.swagger.com.oath.micro.server" }) +public class SwaggerRunnerTest { + + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer(){ + + server = new MicroserverApp( SwaggerRunnerTest.class, ()-> "swagger-app"); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + + + assertThat(rest.getJson("http://localhost:8080/api-docs/stats"),containsString("Make a ping call")); + + } + + + +} diff --git a/micro-swagger/src/test/java/com/aol/micro/server/rest/swagger/ServletStatusResource.java b/micro-swagger/src/test/java/com/aol/micro/server/rest/swagger/ServletStatusResource.java deleted file mode 100644 index cb9d826ef..000000000 --- a/micro-swagger/src/test/java/com/aol/micro/server/rest/swagger/ServletStatusResource.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.aol.micro.server.rest.swagger; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.RestResource; - -@Component -@Path("/servlet") -public class ServletStatusResource implements RestResource { - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "ok"; - } - -} \ No newline at end of file diff --git a/micro-swagger/src/test/java/com/aol/micro/server/testing/RestAgent.java b/micro-swagger/src/test/java/com/aol/micro/server/testing/RestAgent.java deleted file mode 100644 index ce204f810..000000000 --- a/micro-swagger/src/test/java/com/aol/micro/server/testing/RestAgent.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.aol.micro.server.testing; - -import java.util.List; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.Invocation.Builder; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; - -import com.aol.micro.server.rest.jackson.JacksonUtil; - -public class RestAgent { - - - public String getJson(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.get(String.class); - - } - - public String get(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.TEXT_PLAIN); - - return request.get(String.class); - - } - - public T post(String url, Object payload,Class type) { - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); - } - - -} diff --git a/micro-swagger/src/test/java/com/oath/micro/server/rest/swagger/ServletStatusResource.java b/micro-swagger/src/test/java/com/oath/micro/server/rest/swagger/ServletStatusResource.java new file mode 100644 index 000000000..434d0af4a --- /dev/null +++ b/micro-swagger/src/test/java/com/oath/micro/server/rest/swagger/ServletStatusResource.java @@ -0,0 +1,22 @@ +package com.oath.micro.server.rest.swagger; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.RestResource; + +@Component +@Path("/servlet") +public class ServletStatusResource implements RestResource { + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "ok"; + } + +} \ No newline at end of file diff --git a/micro-swagger/src/test/java/com/aol/micro/server/rest/swagger/SwaggerInitializerTest.java b/micro-swagger/src/test/java/com/oath/micro/server/rest/swagger/SwaggerInitializerTest.java similarity index 84% rename from micro-swagger/src/test/java/com/aol/micro/server/rest/swagger/SwaggerInitializerTest.java rename to micro-swagger/src/test/java/com/oath/micro/server/rest/swagger/SwaggerInitializerTest.java index 78b0dabb6..f84fbd24f 100644 --- a/micro-swagger/src/test/java/com/aol/micro/server/rest/swagger/SwaggerInitializerTest.java +++ b/micro-swagger/src/test/java/com/oath/micro/server/rest/swagger/SwaggerInitializerTest.java @@ -1,10 +1,10 @@ -package com.aol.micro.server.rest.swagger; +package com.oath.micro.server.rest.swagger; import cyclops.collections.immutable.LinkedListX; import org.junit.Test; -import com.aol.micro.server.servers.model.ServerData; +import com.oath.micro.server.servers.model.ServerData; import com.google.common.collect.ImmutableList; public class SwaggerInitializerTest { diff --git a/micro-swagger/src/test/java/com/oath/micro/server/testing/RestAgent.java b/micro-swagger/src/test/java/com/oath/micro/server/testing/RestAgent.java new file mode 100644 index 000000000..b2b86303e --- /dev/null +++ b/micro-swagger/src/test/java/com/oath/micro/server/testing/RestAgent.java @@ -0,0 +1,53 @@ +package com.oath.micro.server.testing; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.Invocation.Builder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; + +import com.oath.micro.server.rest.jackson.JacksonUtil; + +public class RestAgent { + + + public String getJson(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.get(String.class); + + } + + public String get(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.TEXT_PLAIN); + + return request.get(String.class); + + } + + public T post(String url, Object payload,Class type) { + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); + } + + +} diff --git a/micro-tomcat-with-jersey/src/test/java/app/access/log/micro/server/servers/AccessLogConfigTest.java b/micro-tomcat-with-jersey/src/test/java/app/access/log/micro/server/servers/AccessLogConfigTest.java index 275aa8b17..7fff1987b 100644 --- a/micro-tomcat-with-jersey/src/test/java/app/access/log/micro/server/servers/AccessLogConfigTest.java +++ b/micro-tomcat-with-jersey/src/test/java/app/access/log/micro/server/servers/AccessLogConfigTest.java @@ -11,8 +11,8 @@ import org.junit.Before; import org.junit.Test; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; @Microserver(properties={"access.log.output", "${user.home}"}) public class AccessLogConfigTest { diff --git a/micro-tomcat-with-jersey/src/test/java/app/async/com/aol/micro/server/AsyncAppRunner.java b/micro-tomcat-with-jersey/src/test/java/app/async/com/aol/micro/server/AsyncAppRunner.java deleted file mode 100644 index a5b427b75..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/async/com/aol/micro/server/AsyncAppRunner.java +++ /dev/null @@ -1,58 +0,0 @@ -package app.async.com.aol.micro.server; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.io.IOException; -import java.util.Properties; -import java.util.concurrent.ExecutionException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.spring.properties.PropertyFileConfig; -import com.aol.micro.server.testing.RestAgent; - -@Microserver -public class AsyncAppRunner { - - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer() throws InterruptedException{ - - server = new MicroserverApp( ()-> "async-app"); - Thread.sleep(1000); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - Thread.sleep(2000); - - assertThat(rest.get("http://localhost:8080/async-app/async/expensive"),is(";test!;test!;test!")); - - } - - @Test - public void loadProperties() throws IOException{ - - Properties props = new PropertyFileConfig(true).propertyFactory() ; - assertThat(props.getProperty("test"),is("hello world")); - } - - - -} \ No newline at end of file diff --git a/micro-tomcat-with-jersey/src/test/java/app/async/com/aol/micro/server/AsyncResource.java b/micro-tomcat-with-jersey/src/test/java/app/async/com/aol/micro/server/AsyncResource.java deleted file mode 100644 index 34f8f0079..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/async/com/aol/micro/server/AsyncResource.java +++ /dev/null @@ -1,57 +0,0 @@ -package app.async.com.aol.micro.server; - -import java.util.Arrays; -import java.util.List; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.container.AsyncResponse; -import javax.ws.rs.container.Suspended; - -import cyclops.async.SimpleReact; -import cyclops.reactive.FutureStream; -import cyclops.reactive.ReactiveSeq; -import org.springframework.stereotype.Component; - - -import com.aol.micro.server.auto.discovery.RestResource; -import com.aol.micro.server.testing.RestAgent; - -@Path("/async") -@Component -public class AsyncResource implements RestResource{ - - private final SimpleReact simpleReact =new SimpleReact(); - private final List urls = Arrays.asList("http://localhost:8080/async-app/async/ping2", - "http://localhost:8080/async-app/async/ping", - "http://localhost:8080/async-app/async/ping", - "http://localhost:8080/async-app/async/ping"); - - private final RestAgent client = new RestAgent(); - - @GET - @Path("/expensive") - @Produces("text/plain") - public void expensive(@Suspended AsyncResponse asyncResponse){ - - FutureStream.builder().fromIterable(urls) - .then(it->client.get(it)) - .onFail(it -> "") - .peek(it -> - System.out.println(it)) - .convertToSimpleReact() - .allOf(data -> { - System.out.println(data); - return asyncResponse.resume(ReactiveSeq.fromIterable(data).join(";")); }); - } - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "test!"; - } - - -} diff --git a/micro-tomcat-with-jersey/src/test/java/app/async/com/aol/micro/server/Simple.java b/micro-tomcat-with-jersey/src/test/java/app/async/com/aol/micro/server/Simple.java deleted file mode 100644 index edefa80ef..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/async/com/aol/micro/server/Simple.java +++ /dev/null @@ -1,16 +0,0 @@ -package app.async.com.aol.micro.server; - -import java.io.IOException; -import java.util.Properties; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Config; -import com.aol.micro.server.spring.properties.PropertyFileConfig; - -public class Simple { - - public static void main(String[] args) throws IOException{ - - new MicroserverApp(()->"test-app").run(); - } -} diff --git a/micro-tomcat-with-jersey/src/test/java/app/async/com/aol/micro/server/SimpleApp.java b/micro-tomcat-with-jersey/src/test/java/app/async/com/aol/micro/server/SimpleApp.java deleted file mode 100644 index 919b7c6b0..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/async/com/aol/micro/server/SimpleApp.java +++ /dev/null @@ -1,24 +0,0 @@ -package app.async.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.Rest; - - - -@Rest -@Path("/test") -public class SimpleApp { - - public static void main(String[] args){ - new MicroserverApp(()->"test-app").run(); - } - @GET - public String myEndPoint(){ - return "hello world!"; - } - - -} diff --git a/micro-tomcat-with-jersey/src/test/java/app/async/com/oath/micro/server/AsyncAppRunner.java b/micro-tomcat-with-jersey/src/test/java/app/async/com/oath/micro/server/AsyncAppRunner.java new file mode 100644 index 000000000..79933ea7a --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/async/com/oath/micro/server/AsyncAppRunner.java @@ -0,0 +1,58 @@ +package app.async.com.oath.micro.server; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.io.IOException; +import java.util.Properties; +import java.util.concurrent.ExecutionException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.spring.properties.PropertyFileConfig; +import com.oath.micro.server.testing.RestAgent; + +@Microserver +public class AsyncAppRunner { + + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer() throws InterruptedException{ + + server = new MicroserverApp( ()-> "async-app"); + Thread.sleep(1000); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + Thread.sleep(2000); + + assertThat(rest.get("http://localhost:8080/async-app/async/expensive"),is(";test!;test!;test!")); + + } + + @Test + public void loadProperties() throws IOException{ + + Properties props = new PropertyFileConfig(true).propertyFactory() ; + assertThat(props.getProperty("test"),is("hello world")); + } + + + +} \ No newline at end of file diff --git a/micro-tomcat-with-jersey/src/test/java/app/async/com/oath/micro/server/AsyncResource.java b/micro-tomcat-with-jersey/src/test/java/app/async/com/oath/micro/server/AsyncResource.java new file mode 100644 index 000000000..3d230ee9b --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/async/com/oath/micro/server/AsyncResource.java @@ -0,0 +1,57 @@ +package app.async.com.oath.micro.server; + +import java.util.Arrays; +import java.util.List; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.container.AsyncResponse; +import javax.ws.rs.container.Suspended; + +import cyclops.async.SimpleReact; +import cyclops.reactive.FutureStream; +import cyclops.reactive.ReactiveSeq; +import org.springframework.stereotype.Component; + + +import com.oath.micro.server.auto.discovery.RestResource; +import com.oath.micro.server.testing.RestAgent; + +@Path("/async") +@Component +public class AsyncResource implements RestResource{ + + private final SimpleReact simpleReact =new SimpleReact(); + private final List urls = Arrays.asList("http://localhost:8080/async-app/async/ping2", + "http://localhost:8080/async-app/async/ping", + "http://localhost:8080/async-app/async/ping", + "http://localhost:8080/async-app/async/ping"); + + private final RestAgent client = new RestAgent(); + + @GET + @Path("/expensive") + @Produces("text/plain") + public void expensive(@Suspended AsyncResponse asyncResponse){ + + FutureStream.builder().fromIterable(urls) + .then(it->client.get(it)) + .onFail(it -> "") + .peek(it -> + System.out.println(it)) + .convertToSimpleReact() + .allOf(data -> { + System.out.println(data); + return asyncResponse.resume(ReactiveSeq.fromIterable(data).join(";")); }); + } + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "test!"; + } + + +} diff --git a/micro-tomcat-with-jersey/src/test/java/app/async/com/oath/micro/server/Simple.java b/micro-tomcat-with-jersey/src/test/java/app/async/com/oath/micro/server/Simple.java new file mode 100644 index 000000000..3eb3e7504 --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/async/com/oath/micro/server/Simple.java @@ -0,0 +1,13 @@ +package app.async.com.oath.micro.server; + +import java.io.IOException; + +import com.oath.micro.server.MicroserverApp; + +public class Simple { + + public static void main(String[] args) throws IOException{ + + new MicroserverApp(()->"test-app").run(); + } +} diff --git a/micro-tomcat-with-jersey/src/test/java/app/async/com/oath/micro/server/SimpleApp.java b/micro-tomcat-with-jersey/src/test/java/app/async/com/oath/micro/server/SimpleApp.java new file mode 100644 index 000000000..916d0330e --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/async/com/oath/micro/server/SimpleApp.java @@ -0,0 +1,24 @@ +package app.async.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.auto.discovery.Rest; + + + +@Rest +@Path("/test") +public class SimpleApp { + + public static void main(String[] args){ + new MicroserverApp(()->"test-app").run(); + } + @GET + public String myEndPoint(){ + return "hello world!"; + } + + +} diff --git a/micro-tomcat-with-jersey/src/test/java/app/blacklisted/com/aol/micro/server/copy/SimpleApp.java b/micro-tomcat-with-jersey/src/test/java/app/blacklisted/com/aol/micro/server/copy/SimpleApp.java deleted file mode 100644 index 37a92de67..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/blacklisted/com/aol/micro/server/copy/SimpleApp.java +++ /dev/null @@ -1,18 +0,0 @@ -package app.blacklisted.com.aol.micro.server.copy; - -import java.util.Arrays; - -import org.glassfish.jersey.media.multipart.MultiPartFeature; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.module.ConfigurableModule; - -public class SimpleApp { - - public static void main(String[] args){ - - new MicroserverApp(()-> "simple-app").run(); - } - - -} diff --git a/micro-tomcat-with-jersey/src/test/java/app/blacklisted/com/aol/micro/server/copy/SimpleRunnerTest.java b/micro-tomcat-with-jersey/src/test/java/app/blacklisted/com/aol/micro/server/copy/SimpleRunnerTest.java deleted file mode 100644 index 010676089..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/blacklisted/com/aol/micro/server/copy/SimpleRunnerTest.java +++ /dev/null @@ -1,57 +0,0 @@ -package app.blacklisted.com.aol.micro.server.copy; - - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.Arrays; -import java.util.concurrent.ExecutionException; - -import nonautoscan.com.aol.micro.server.ScheduleAndAsyncConfig; - -import org.glassfish.jersey.media.multipart.MultiPartFeature; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.testing.RestAgent; - -@Microserver(blacklistedClasses={ScheduleAndAsyncConfig.class}) -public class SimpleRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer() throws InterruptedException{ - server = new MicroserverApp(ConfigurableModule - .builder() - .context("simple-app") - .defaultResources(Arrays.asList(MultiPartFeature.class)) - .build()); - Thread.sleep(1000); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - - - assertThat(rest.get("http://localhost:8080/simple-app/status/ping"),is("ok")); - - - } - - - -} diff --git a/micro-tomcat-with-jersey/src/test/java/app/blacklisted/com/aol/micro/server/copy/SimpleStatusResource.java b/micro-tomcat-with-jersey/src/test/java/app/blacklisted/com/aol/micro/server/copy/SimpleStatusResource.java deleted file mode 100644 index 3ad8426ad..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/blacklisted/com/aol/micro/server/copy/SimpleStatusResource.java +++ /dev/null @@ -1,53 +0,0 @@ -package app.blacklisted.com.aol.micro.server.copy; - -import java.io.InputStream; - -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; - -import nonautoscan.com.aol.micro.server.ScheduleAndAsyncConfig; - -import org.glassfish.jersey.media.multipart.FormDataContentDisposition; -import org.glassfish.jersey.media.multipart.FormDataParam; -import org.junit.Assert; -import org.springframework.beans.factory.NoSuchBeanDefinitionException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; - -import com.aol.micro.server.auto.discovery.Rest; - -@Rest -@Path("/status") -public class SimpleStatusResource { - - @Autowired - ApplicationContext context; - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - - try{ - context.getBean(ScheduleAndAsyncConfig.class); - Assert.fail("failed to remove ScheduleAndAsyncConfig bean!"); - }catch(NoSuchBeanDefinitionException e){ - - } - return "ok"; - } - - @POST - @Consumes(MediaType.MULTIPART_FORM_DATA) - @Produces(MediaType.TEXT_PLAIN) - @Path("/file") - public String create( - @FormDataParam("file") InputStream fileInputStream, - @FormDataParam("file") FormDataContentDisposition contentDispositionHeader) { - - return "done"; - } -} \ No newline at end of file diff --git a/micro-tomcat-with-jersey/src/test/java/app/blacklisted/com/oath/micro/server/copy/SimpleApp.java b/micro-tomcat-with-jersey/src/test/java/app/blacklisted/com/oath/micro/server/copy/SimpleApp.java new file mode 100644 index 000000000..f73582b0c --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/blacklisted/com/oath/micro/server/copy/SimpleApp.java @@ -0,0 +1,13 @@ +package app.blacklisted.com.oath.micro.server.copy; + +import com.oath.micro.server.MicroserverApp; + +public class SimpleApp { + + public static void main(String[] args){ + + new MicroserverApp(()-> "simple-app").run(); + } + + +} diff --git a/micro-tomcat-with-jersey/src/test/java/app/blacklisted/com/oath/micro/server/copy/SimpleRunnerTest.java b/micro-tomcat-with-jersey/src/test/java/app/blacklisted/com/oath/micro/server/copy/SimpleRunnerTest.java new file mode 100644 index 000000000..13c14e435 --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/blacklisted/com/oath/micro/server/copy/SimpleRunnerTest.java @@ -0,0 +1,57 @@ +package app.blacklisted.com.oath.micro.server.copy; + + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.Arrays; +import java.util.concurrent.ExecutionException; + +import nonautoscan.com.oath.micro.server.ScheduleAndAsyncConfig; + +import org.glassfish.jersey.media.multipart.MultiPartFeature; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.module.ConfigurableModule; +import com.oath.micro.server.testing.RestAgent; + +@Microserver(blacklistedClasses={ScheduleAndAsyncConfig.class}) +public class SimpleRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer() throws InterruptedException{ + server = new MicroserverApp(ConfigurableModule + .builder() + .context("simple-app") + .defaultResources(Arrays.asList(MultiPartFeature.class)) + .build()); + Thread.sleep(1000); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + + + assertThat(rest.get("http://localhost:8080/simple-app/status/ping"),is("ok")); + + + } + + + +} diff --git a/micro-tomcat-with-jersey/src/test/java/app/blacklisted/com/oath/micro/server/copy/SimpleStatusResource.java b/micro-tomcat-with-jersey/src/test/java/app/blacklisted/com/oath/micro/server/copy/SimpleStatusResource.java new file mode 100644 index 000000000..4370e7e9a --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/blacklisted/com/oath/micro/server/copy/SimpleStatusResource.java @@ -0,0 +1,53 @@ +package app.blacklisted.com.oath.micro.server.copy; + +import java.io.InputStream; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +import nonautoscan.com.oath.micro.server.ScheduleAndAsyncConfig; + +import org.glassfish.jersey.media.multipart.FormDataContentDisposition; +import org.glassfish.jersey.media.multipart.FormDataParam; +import org.junit.Assert; +import org.springframework.beans.factory.NoSuchBeanDefinitionException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; + +import com.oath.micro.server.auto.discovery.Rest; + +@Rest +@Path("/status") +public class SimpleStatusResource { + + @Autowired + ApplicationContext context; + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + + try{ + context.getBean(ScheduleAndAsyncConfig.class); + Assert.fail("failed to remove ScheduleAndAsyncConfig bean!"); + }catch(NoSuchBeanDefinitionException e){ + + } + return "ok"; + } + + @POST + @Consumes(MediaType.MULTIPART_FORM_DATA) + @Produces(MediaType.TEXT_PLAIN) + @Path("/file") + public String create( + @FormDataParam("file") InputStream fileInputStream, + @FormDataParam("file") FormDataContentDisposition contentDispositionHeader) { + + return "done"; + } +} \ No newline at end of file diff --git a/micro-tomcat-with-jersey/src/test/java/app/custom/binder/test/SimpleApp.java b/micro-tomcat-with-jersey/src/test/java/app/custom/binder/test/SimpleApp.java index 7a2c74e08..2e275f0bd 100644 --- a/micro-tomcat-with-jersey/src/test/java/app/custom/binder/test/SimpleApp.java +++ b/micro-tomcat-with-jersey/src/test/java/app/custom/binder/test/SimpleApp.java @@ -5,9 +5,9 @@ import org.glassfish.jersey.server.ResourceConfig; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.module.ConfigurableModule; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.auto.discovery.Rest; +import com.oath.micro.server.module.ConfigurableModule; diff --git a/micro-tomcat-with-jersey/src/test/java/app/embedded/com/aol/micro/server/AltAppResource.java b/micro-tomcat-with-jersey/src/test/java/app/embedded/com/aol/micro/server/AltAppResource.java deleted file mode 100644 index d4b8eff5c..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/embedded/com/aol/micro/server/AltAppResource.java +++ /dev/null @@ -1,23 +0,0 @@ -package app.embedded.com.aol.micro.server; - -import java.util.ArrayList; -import java.util.List; - -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.stereotype.Component; - -@Component -@Path("/alt-status") -public class AltAppResource implements AltAppRestResource { - - @POST - @Produces("application/json") - @Path("/ping") - public List ping(ImmutableEntity entity) { - return entity.getList(); - } - -} diff --git a/micro-tomcat-with-jersey/src/test/java/app/embedded/com/aol/micro/server/AltAppRestResource.java b/micro-tomcat-with-jersey/src/test/java/app/embedded/com/aol/micro/server/AltAppRestResource.java deleted file mode 100644 index 8cb2643e3..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/embedded/com/aol/micro/server/AltAppRestResource.java +++ /dev/null @@ -1,7 +0,0 @@ -package app.embedded.com.aol.micro.server; - -import com.aol.micro.server.auto.discovery.RestResource; - -public interface AltAppRestResource extends RestResource { - -} diff --git a/micro-tomcat-with-jersey/src/test/java/app/embedded/com/aol/micro/server/EmbeddedAppLocalMain.java b/micro-tomcat-with-jersey/src/test/java/app/embedded/com/aol/micro/server/EmbeddedAppLocalMain.java deleted file mode 100644 index bc73c2862..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/embedded/com/aol/micro/server/EmbeddedAppLocalMain.java +++ /dev/null @@ -1,24 +0,0 @@ -package app.embedded.com.aol.micro.server; - -import java.util.Arrays; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.module.EmbeddedModule; - -@Microserver(basePackages = { "app.embedded.com.aol.micro.server" }) -public class EmbeddedAppLocalMain { - - - public static void main(String[] args) throws InterruptedException { - - new MicroserverApp( - EmbeddedModule.tagInterfaceModule(Arrays.asList(TestAppRestResource.class),"test-app"), - EmbeddedModule.tagInterfaceModule(Arrays.asList(AltAppRestResource.class),"alternative-app")).start(); - - - - } - - -} diff --git a/micro-tomcat-with-jersey/src/test/java/app/embedded/com/aol/micro/server/EmbeddedAppTest.java b/micro-tomcat-with-jersey/src/test/java/app/embedded/com/aol/micro/server/EmbeddedAppTest.java deleted file mode 100644 index efe66003c..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/embedded/com/aol/micro/server/EmbeddedAppTest.java +++ /dev/null @@ -1,104 +0,0 @@ -package app.embedded.com.aol.micro.server; - -import static org.hamcrest.Matchers.hasItem; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; - -import javax.ws.rs.NotFoundException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.springframework.util.concurrent.ListenableFuture; -import org.springframework.util.concurrent.ListenableFutureCallback; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.module.EmbeddedModule; -import com.aol.micro.server.testing.RestAgent; - -@Ignore //embedded - micro-monolith style doesn't work with Tomcat due to MBean naming collisions -public class EmbeddedAppTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - - @Before - public void startServer(){ - server = new MicroserverApp(EmbeddedAppLocalMain.class, - EmbeddedModule.tagInterfaceModule(Arrays.asList(TestAppRestResource.class),"test-app"), - EmbeddedModule.tagInterfaceModule(Arrays.asList(AltAppRestResource.class),"alternative-app")); - server.start(); - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void confirmExpectedUrlsPresentTest() throws InterruptedException, ExecutionException{ - - assertThat(rest.get("http://localhost:8080/test-app/test-status/ping"),is("test!")); - - - assertThat((List)rest.post("http://localhost:8081/alternative-app/alt-status/ping",new ImmutableEntity("value",Arrays.asList("hello","world")),List.class), - hasItem("hello")); - - } - - - @Test - public void nonBlockingRestClientTest(){ - assertThat(rest.get("http://localhost:8080/test-app/test-status/rest-calls"),is("-*test!-*test!")); - } - - CompletableFuture toCompletableFuture( - final ListenableFuture listenableFuture - ) { - //create an instance of CompletableFuture - CompletableFuture completable = new CompletableFuture() { - @Override - public boolean cancel(boolean mayInterruptIfRunning) { - // propagate cancel to the listenable future - boolean result = listenableFuture.cancel(mayInterruptIfRunning); - super.cancel(mayInterruptIfRunning); - return result; - } - }; - - // add callback - listenableFuture.addCallback(new ListenableFutureCallback() { - @Override - public void onSuccess(T result) { - completable.complete(result); - } - - @Override - public void onFailure(Throwable t) { - completable.completeExceptionally(t); - } - }); - return completable; - } - - @Test(expected=NotFoundException.class) - public void confirmAltAppCantUseTestAppResources(){ - - assertThat(rest.get("http://localhost:8080/alternative-app/test-status/ping"),is("test!")); - - } - @Test(expected=NotFoundException.class) - public void confirmTestAppCantUseAltAppResources(){ - - assertThat((List)rest.post("http://localhost:8081/test-app/alt-status/ping",new ImmutableEntity("value",Arrays.asList("hello","world")),List.class), - hasItem("hello")); - - } -} diff --git a/micro-tomcat-with-jersey/src/test/java/app/embedded/com/aol/micro/server/ImmutableEntity.java b/micro-tomcat-with-jersey/src/test/java/app/embedded/com/aol/micro/server/ImmutableEntity.java deleted file mode 100644 index cd593f123..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/embedded/com/aol/micro/server/ImmutableEntity.java +++ /dev/null @@ -1,29 +0,0 @@ -package app.embedded.com.aol.micro.server; - -import java.util.List; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Builder; - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "") -@XmlRootElement(name = "immutable") -@Getter -@AllArgsConstructor -@Builder -public class ImmutableEntity { - - private final String value; - private final List list; - - public ImmutableEntity() { - this(null,null); - } - -} diff --git a/micro-tomcat-with-jersey/src/test/java/app/embedded/com/aol/micro/server/TestAppResource.java b/micro-tomcat-with-jersey/src/test/java/app/embedded/com/aol/micro/server/TestAppResource.java deleted file mode 100644 index 06970bb57..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/embedded/com/aol/micro/server/TestAppResource.java +++ /dev/null @@ -1,48 +0,0 @@ -package app.embedded.com.aol.micro.server; - -import java.util.Arrays; -import java.util.List; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import cyclops.async.SimpleReact; -import cyclops.reactive.FutureStream; -import org.springframework.stereotype.Component; - -import com.aol.micro.server.testing.RestAgent; -@Component -@Path("/test-status") -public class TestAppResource implements TestAppRestResource { - - private final SimpleReact simpleReact = new SimpleReact(); - private final RestAgent template = new RestAgent(); - private final List urls = Arrays.asList("http://localhost:8081/alternative-app/alt-status/ping", - "http://localhost:8080/test-app/test-status/ping", - "http://localhost:8082/simple-app/status/ping", - "http://localhost:8080/test-app/test-status/ping"); - - - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "test!"; - } - - @GET - @Produces("text/plain") - @Path("/rest-calls") - public String restCallResult(){ - - return FutureStream.builder().fromIterable(urls) - .map(it ->template.get(it)) - .then(it -> "*"+it) - .peek(loadedAndModified -> System.out.println(loadedAndModified)) - .block().stream().reduce("", (acc,next) -> acc+"-"+next); - - } - -} diff --git a/micro-tomcat-with-jersey/src/test/java/app/embedded/com/aol/micro/server/TestAppRestResource.java b/micro-tomcat-with-jersey/src/test/java/app/embedded/com/aol/micro/server/TestAppRestResource.java deleted file mode 100644 index 3133fd8cc..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/embedded/com/aol/micro/server/TestAppRestResource.java +++ /dev/null @@ -1,7 +0,0 @@ -package app.embedded.com.aol.micro.server; - -import com.aol.micro.server.auto.discovery.RestResource; - -public interface TestAppRestResource extends RestResource { - -} diff --git a/micro-tomcat-with-jersey/src/test/java/app/embedded/com/oath/micro/server/AltAppResource.java b/micro-tomcat-with-jersey/src/test/java/app/embedded/com/oath/micro/server/AltAppResource.java new file mode 100644 index 000000000..1835ababe --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/embedded/com/oath/micro/server/AltAppResource.java @@ -0,0 +1,22 @@ +package app.embedded.com.oath.micro.server; + +import java.util.List; + +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.stereotype.Component; + +@Component +@Path("/alt-status") +public class AltAppResource implements AltAppRestResource { + + @POST + @Produces("application/json") + @Path("/ping") + public List ping(ImmutableEntity entity) { + return entity.getList(); + } + +} diff --git a/micro-tomcat-with-jersey/src/test/java/app/embedded/com/oath/micro/server/AltAppRestResource.java b/micro-tomcat-with-jersey/src/test/java/app/embedded/com/oath/micro/server/AltAppRestResource.java new file mode 100644 index 000000000..7045a4f35 --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/embedded/com/oath/micro/server/AltAppRestResource.java @@ -0,0 +1,7 @@ +package app.embedded.com.oath.micro.server; + +import com.oath.micro.server.auto.discovery.RestResource; + +public interface AltAppRestResource extends RestResource { + +} diff --git a/micro-tomcat-with-jersey/src/test/java/app/embedded/com/oath/micro/server/EmbeddedAppLocalMain.java b/micro-tomcat-with-jersey/src/test/java/app/embedded/com/oath/micro/server/EmbeddedAppLocalMain.java new file mode 100644 index 000000000..dbb290069 --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/embedded/com/oath/micro/server/EmbeddedAppLocalMain.java @@ -0,0 +1,24 @@ +package app.embedded.com.oath.micro.server; + +import java.util.Arrays; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.module.EmbeddedModule; + +@Microserver(basePackages = { "app.embedded.com.oath.micro.server" }) +public class EmbeddedAppLocalMain { + + + public static void main(String[] args) throws InterruptedException { + + new MicroserverApp( + EmbeddedModule.tagInterfaceModule(Arrays.asList(TestAppRestResource.class),"test-app"), + EmbeddedModule.tagInterfaceModule(Arrays.asList(AltAppRestResource.class),"alternative-app")).start(); + + + + } + + +} diff --git a/micro-tomcat-with-jersey/src/test/java/app/embedded/com/oath/micro/server/EmbeddedAppTest.java b/micro-tomcat-with-jersey/src/test/java/app/embedded/com/oath/micro/server/EmbeddedAppTest.java new file mode 100644 index 000000000..bc2c5e09b --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/embedded/com/oath/micro/server/EmbeddedAppTest.java @@ -0,0 +1,104 @@ +package app.embedded.com.oath.micro.server; + +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; + +import javax.ws.rs.NotFoundException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.springframework.util.concurrent.ListenableFuture; +import org.springframework.util.concurrent.ListenableFutureCallback; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.module.EmbeddedModule; +import com.oath.micro.server.testing.RestAgent; + +@Ignore //embedded - micro-monolith style doesn't work with Tomcat due to MBean naming collisions +public class EmbeddedAppTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + + @Before + public void startServer(){ + server = new MicroserverApp(EmbeddedAppLocalMain.class, + EmbeddedModule.tagInterfaceModule(Arrays.asList(TestAppRestResource.class),"test-app"), + EmbeddedModule.tagInterfaceModule(Arrays.asList(AltAppRestResource.class),"alternative-app")); + server.start(); + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void confirmExpectedUrlsPresentTest() throws InterruptedException, ExecutionException{ + + assertThat(rest.get("http://localhost:8080/test-app/test-status/ping"),is("test!")); + + + assertThat((List)rest.post("http://localhost:8081/alternative-app/alt-status/ping",new ImmutableEntity("value",Arrays.asList("hello","world")),List.class), + hasItem("hello")); + + } + + + @Test + public void nonBlockingRestClientTest(){ + assertThat(rest.get("http://localhost:8080/test-app/test-status/rest-calls"),is("-*test!-*test!")); + } + + CompletableFuture toCompletableFuture( + final ListenableFuture listenableFuture + ) { + //create an instance of CompletableFuture + CompletableFuture completable = new CompletableFuture() { + @Override + public boolean cancel(boolean mayInterruptIfRunning) { + // propagate cancel to the listenable future + boolean result = listenableFuture.cancel(mayInterruptIfRunning); + super.cancel(mayInterruptIfRunning); + return result; + } + }; + + // add callback + listenableFuture.addCallback(new ListenableFutureCallback() { + @Override + public void onSuccess(T result) { + completable.complete(result); + } + + @Override + public void onFailure(Throwable t) { + completable.completeExceptionally(t); + } + }); + return completable; + } + + @Test(expected=NotFoundException.class) + public void confirmAltAppCantUseTestAppResources(){ + + assertThat(rest.get("http://localhost:8080/alternative-app/test-status/ping"),is("test!")); + + } + @Test(expected=NotFoundException.class) + public void confirmTestAppCantUseAltAppResources(){ + + assertThat((List)rest.post("http://localhost:8081/test-app/alt-status/ping",new ImmutableEntity("value",Arrays.asList("hello","world")),List.class), + hasItem("hello")); + + } +} diff --git a/micro-tomcat-with-jersey/src/test/java/app/embedded/com/oath/micro/server/ImmutableEntity.java b/micro-tomcat-with-jersey/src/test/java/app/embedded/com/oath/micro/server/ImmutableEntity.java new file mode 100644 index 000000000..337b63b89 --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/embedded/com/oath/micro/server/ImmutableEntity.java @@ -0,0 +1,29 @@ +package app.embedded.com.oath.micro.server; + +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Builder; + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "") +@XmlRootElement(name = "immutable") +@Getter +@AllArgsConstructor +@Builder +public class ImmutableEntity { + + private final String value; + private final List list; + + public ImmutableEntity() { + this(null,null); + } + +} diff --git a/micro-tomcat-with-jersey/src/test/java/app/embedded/com/oath/micro/server/TestAppResource.java b/micro-tomcat-with-jersey/src/test/java/app/embedded/com/oath/micro/server/TestAppResource.java new file mode 100644 index 000000000..bc65715c7 --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/embedded/com/oath/micro/server/TestAppResource.java @@ -0,0 +1,48 @@ +package app.embedded.com.oath.micro.server; + +import java.util.Arrays; +import java.util.List; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import cyclops.async.SimpleReact; +import cyclops.reactive.FutureStream; +import org.springframework.stereotype.Component; + +import com.oath.micro.server.testing.RestAgent; +@Component +@Path("/test-status") +public class TestAppResource implements TestAppRestResource { + + private final SimpleReact simpleReact = new SimpleReact(); + private final RestAgent template = new RestAgent(); + private final List urls = Arrays.asList("http://localhost:8081/alternative-app/alt-status/ping", + "http://localhost:8080/test-app/test-status/ping", + "http://localhost:8082/simple-app/status/ping", + "http://localhost:8080/test-app/test-status/ping"); + + + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "test!"; + } + + @GET + @Produces("text/plain") + @Path("/rest-calls") + public String restCallResult(){ + + return FutureStream.builder().fromIterable(urls) + .map(it ->template.get(it)) + .then(it -> "*"+it) + .peek(loadedAndModified -> System.out.println(loadedAndModified)) + .block().stream().reduce("", (acc,next) -> acc+"-"+next); + + } + +} diff --git a/micro-tomcat-with-jersey/src/test/java/app/embedded/com/oath/micro/server/TestAppRestResource.java b/micro-tomcat-with-jersey/src/test/java/app/embedded/com/oath/micro/server/TestAppRestResource.java new file mode 100644 index 000000000..7d4df5753 --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/embedded/com/oath/micro/server/TestAppRestResource.java @@ -0,0 +1,7 @@ +package app.embedded.com.oath.micro.server; + +import com.oath.micro.server.auto.discovery.RestResource; + +public interface TestAppRestResource extends RestResource { + +} diff --git a/micro-tomcat-with-jersey/src/test/java/app/filter/com/aol/micro/server/AutodiscoveredFilter.java b/micro-tomcat-with-jersey/src/test/java/app/filter/com/aol/micro/server/AutodiscoveredFilter.java deleted file mode 100644 index 52a8959db..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/filter/com/aol/micro/server/AutodiscoveredFilter.java +++ /dev/null @@ -1,70 +0,0 @@ -package app.filter.com.aol.micro.server; - -import java.io.IOException; - -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; - -import cyclops.control.Either; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - - -import com.aol.micro.server.auto.discovery.AutoFilterConfiguration; - -import lombok.Getter; -import lombok.Setter; - -@Component -public class AutodiscoveredFilter implements AutoFilterConfiguration { - - @Autowired - Bean bean; - @Getter - @Setter - private static volatile int called= 0; - - @Getter - private static boolean beanSet = false; - - @Override - public String[] getMapping() { - return new String[] { "/*" }; - } - public Either,Filter> getFilter(){ - - return Either.left(org.springframework.web.filter.DelegatingFilterProxy.class); - - } - public String getName(){ - return "autodiscoveredFilter"; - } - - @Override - public void init(FilterConfig filterConfig) throws ServletException { - - } - - @Override - public void doFilter(ServletRequest request, ServletResponse response, - FilterChain chain) throws IOException, ServletException { - - called++; - if(bean!=null) - beanSet =true; - chain.doFilter(request, response); - } - - @Override - public void destroy() { - - - } - - - -} \ No newline at end of file diff --git a/micro-tomcat-with-jersey/src/test/java/app/filter/com/aol/micro/server/Bean.java b/micro-tomcat-with-jersey/src/test/java/app/filter/com/aol/micro/server/Bean.java deleted file mode 100644 index f95b44b05..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/filter/com/aol/micro/server/Bean.java +++ /dev/null @@ -1,8 +0,0 @@ -package app.filter.com.aol.micro.server; - -import org.springframework.stereotype.Component; - -@Component -public class Bean { - -} diff --git a/micro-tomcat-with-jersey/src/test/java/app/filter/com/aol/micro/server/ConfiguredFilter.java b/micro-tomcat-with-jersey/src/test/java/app/filter/com/aol/micro/server/ConfiguredFilter.java deleted file mode 100644 index e00bc941b..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/filter/com/aol/micro/server/ConfiguredFilter.java +++ /dev/null @@ -1,38 +0,0 @@ -package app.filter.com.aol.micro.server; - -import java.io.IOException; - -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; - -import lombok.Getter; - -public class ConfiguredFilter implements Filter { - - @Getter - private static volatile int called= 0; - @Override - public void init(FilterConfig filterConfig) throws ServletException { - // TODO Auto-generated method stub - - } - - @Override - public void doFilter(ServletRequest request, ServletResponse response, - FilterChain chain) throws IOException, ServletException { - called++; - chain.doFilter(request, response); - - } - - @Override - public void destroy() { - // TODO Auto-generated method stub - - } - -} diff --git a/micro-tomcat-with-jersey/src/test/java/app/filter/com/aol/micro/server/FilterAppLocalMain.java b/micro-tomcat-with-jersey/src/test/java/app/filter/com/aol/micro/server/FilterAppLocalMain.java deleted file mode 100644 index 25dc01cc3..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/filter/com/aol/micro/server/FilterAppLocalMain.java +++ /dev/null @@ -1,22 +0,0 @@ -package app.filter.com.aol.micro.server; - -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; - -import app.servlet.com.aol.micro.server.AppRunnerLocalMain; - -import com.aol.micro.server.MicroserverApp; -@Configuration -@ComponentScan(basePackages = { "app.filter.com.aol.micro.server" }) -public class FilterAppLocalMain { - - - - - public static void main(String[] args) throws InterruptedException { - - new MicroserverApp( FilterAppLocalMain.class, () -> "filter-app") - .run(); - } - - } \ No newline at end of file diff --git a/micro-tomcat-with-jersey/src/test/java/app/filter/com/aol/micro/server/FilterRunnerTest.java b/micro-tomcat-with-jersey/src/test/java/app/filter/com/aol/micro/server/FilterRunnerTest.java deleted file mode 100644 index a2f2acec9..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/filter/com/aol/micro/server/FilterRunnerTest.java +++ /dev/null @@ -1,65 +0,0 @@ -package app.filter.com.aol.micro.server; - - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.Arrays; -import java.util.Map; -import java.util.concurrent.ExecutionException; - -import javax.servlet.Filter; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.testing.RestAgent; -import com.aol.micro.server.utility.HashMapBuilder; - - - -public class FilterRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer() throws InterruptedException{ - Map filters = HashMapBuilder.map("/filter-app/status/ping2",new ConfiguredFilter()).build(); - server = new MicroserverApp(ConfigurableModule.builder() - .context("filter-app") - .filters(filters ) - .requestListeners(Arrays.asList(new org.springframework.web.context.request.RequestContextListener())).build()); - Thread.sleep(1000); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void testAutoDiscoveredFilter() throws InterruptedException, ExecutionException{ - AutodiscoveredFilter.setCalled(0); - - assertThat(rest.get("http://localhost:8080/filter-app/status/ping"),is("ok")); - assertThat(AutodiscoveredFilter.getCalled(),is(1)); - assertThat(AutodiscoveredFilter.isBeanSet(),is(true)); - } - @Test - public void testConfiguredFilter() throws InterruptedException, ExecutionException{ - - assertThat(ConfiguredFilter.getCalled(),is(0)); - assertThat(rest.get("http://localhost:8080/filter-app/status/ping2"),is("ok")); - assertThat(ConfiguredFilter.getCalled(),is(1)); - } - - - - -} diff --git a/micro-tomcat-with-jersey/src/test/java/app/filter/com/aol/micro/server/FilterStatusResource.java b/micro-tomcat-with-jersey/src/test/java/app/filter/com/aol/micro/server/FilterStatusResource.java deleted file mode 100644 index 2d046711b..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/filter/com/aol/micro/server/FilterStatusResource.java +++ /dev/null @@ -1,37 +0,0 @@ -package app.filter.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.config.ConfigurableBeanFactory; -import org.springframework.context.annotation.Scope; -import org.springframework.stereotype.Component; -import org.springframework.web.context.WebApplicationContext; - -import com.aol.micro.server.auto.discovery.RestResource; - -@Component -@Scope(value=ConfigurableBeanFactory.SCOPE_PROTOTYPE) -@Path("/status") -public class FilterStatusResource implements RestResource { - - @Autowired - private RequestScopeUserInfo info; - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - info.print(); - return "ok"; - } - @GET - @Produces("text/plain") - @Path("/ping2") - public String ping2() { - return "ok"; - } - -} \ No newline at end of file diff --git a/micro-tomcat-with-jersey/src/test/java/app/filter/com/aol/micro/server/RequestScopeUserInfo.java b/micro-tomcat-with-jersey/src/test/java/app/filter/com/aol/micro/server/RequestScopeUserInfo.java deleted file mode 100644 index c41605c39..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/filter/com/aol/micro/server/RequestScopeUserInfo.java +++ /dev/null @@ -1,20 +0,0 @@ -package app.filter.com.aol.micro.server; - -import javax.servlet.http.HttpServletRequest; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Scope; -import org.springframework.context.annotation.ScopedProxyMode; -import org.springframework.stereotype.Component; -import org.springframework.web.context.WebApplicationContext; - -@Component -@Scope(value=WebApplicationContext.SCOPE_REQUEST,proxyMode=ScopedProxyMode.TARGET_CLASS) -public class RequestScopeUserInfo { - @Autowired - private HttpServletRequest request; - - public void print(){ - System.out.println(request.getAttribute("oc.info")); - } -} diff --git a/micro-tomcat-with-jersey/src/test/java/app/filter/com/oath/micro/server/AutodiscoveredFilter.java b/micro-tomcat-with-jersey/src/test/java/app/filter/com/oath/micro/server/AutodiscoveredFilter.java new file mode 100644 index 000000000..1f6dfc284 --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/filter/com/oath/micro/server/AutodiscoveredFilter.java @@ -0,0 +1,70 @@ +package app.filter.com.oath.micro.server; + +import java.io.IOException; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; + +import cyclops.control.Either; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + + +import com.oath.micro.server.auto.discovery.AutoFilterConfiguration; + +import lombok.Getter; +import lombok.Setter; + +@Component +public class AutodiscoveredFilter implements AutoFilterConfiguration { + + @Autowired + Bean bean; + @Getter + @Setter + private static volatile int called= 0; + + @Getter + private static boolean beanSet = false; + + @Override + public String[] getMapping() { + return new String[] { "/*" }; + } + public Either,Filter> getFilter(){ + + return Either.left(org.springframework.web.filter.DelegatingFilterProxy.class); + + } + public String getName(){ + return "autodiscoveredFilter"; + } + + @Override + public void init(FilterConfig filterConfig) throws ServletException { + + } + + @Override + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + called++; + if(bean!=null) + beanSet =true; + chain.doFilter(request, response); + } + + @Override + public void destroy() { + + + } + + + +} \ No newline at end of file diff --git a/micro-tomcat-with-jersey/src/test/java/app/filter/com/oath/micro/server/Bean.java b/micro-tomcat-with-jersey/src/test/java/app/filter/com/oath/micro/server/Bean.java new file mode 100644 index 000000000..e036a796f --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/filter/com/oath/micro/server/Bean.java @@ -0,0 +1,8 @@ +package app.filter.com.oath.micro.server; + +import org.springframework.stereotype.Component; + +@Component +public class Bean { + +} diff --git a/micro-tomcat-with-jersey/src/test/java/app/filter/com/oath/micro/server/ConfiguredFilter.java b/micro-tomcat-with-jersey/src/test/java/app/filter/com/oath/micro/server/ConfiguredFilter.java new file mode 100644 index 000000000..aca52ad38 --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/filter/com/oath/micro/server/ConfiguredFilter.java @@ -0,0 +1,38 @@ +package app.filter.com.oath.micro.server; + +import java.io.IOException; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; + +import lombok.Getter; + +public class ConfiguredFilter implements Filter { + + @Getter + private static volatile int called= 0; + @Override + public void init(FilterConfig filterConfig) throws ServletException { + // TODO Auto-generated method stub + + } + + @Override + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + called++; + chain.doFilter(request, response); + + } + + @Override + public void destroy() { + // TODO Auto-generated method stub + + } + +} diff --git a/micro-tomcat-with-jersey/src/test/java/app/filter/com/oath/micro/server/FilterAppLocalMain.java b/micro-tomcat-with-jersey/src/test/java/app/filter/com/oath/micro/server/FilterAppLocalMain.java new file mode 100644 index 000000000..b650780a2 --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/filter/com/oath/micro/server/FilterAppLocalMain.java @@ -0,0 +1,20 @@ +package app.filter.com.oath.micro.server; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +import com.oath.micro.server.MicroserverApp; +@Configuration +@ComponentScan(basePackages = { "app.filter.com.aol.micro.server" }) +public class FilterAppLocalMain { + + + + + public static void main(String[] args) throws InterruptedException { + + new MicroserverApp( FilterAppLocalMain.class, () -> "filter-app") + .run(); + } + + } \ No newline at end of file diff --git a/micro-tomcat-with-jersey/src/test/java/app/filter/com/oath/micro/server/FilterRunnerTest.java b/micro-tomcat-with-jersey/src/test/java/app/filter/com/oath/micro/server/FilterRunnerTest.java new file mode 100644 index 000000000..0887a38ab --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/filter/com/oath/micro/server/FilterRunnerTest.java @@ -0,0 +1,65 @@ +package app.filter.com.oath.micro.server; + + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.Arrays; +import java.util.Map; +import java.util.concurrent.ExecutionException; + +import javax.servlet.Filter; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.module.ConfigurableModule; +import com.oath.micro.server.testing.RestAgent; +import com.oath.micro.server.utility.HashMapBuilder; + + + +public class FilterRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer() throws InterruptedException{ + Map filters = HashMapBuilder.map("/filter-app/status/ping2",new ConfiguredFilter()).build(); + server = new MicroserverApp(ConfigurableModule.builder() + .context("filter-app") + .filters(filters ) + .requestListeners(Arrays.asList(new org.springframework.web.context.request.RequestContextListener())).build()); + Thread.sleep(1000); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void testAutoDiscoveredFilter() throws InterruptedException, ExecutionException{ + AutodiscoveredFilter.setCalled(0); + + assertThat(rest.get("http://localhost:8080/filter-app/status/ping"),is("ok")); + assertThat(AutodiscoveredFilter.getCalled(),is(1)); + assertThat(AutodiscoveredFilter.isBeanSet(),is(true)); + } + @Test + public void testConfiguredFilter() throws InterruptedException, ExecutionException{ + + assertThat(ConfiguredFilter.getCalled(),is(0)); + assertThat(rest.get("http://localhost:8080/filter-app/status/ping2"),is("ok")); + assertThat(ConfiguredFilter.getCalled(),is(1)); + } + + + + +} diff --git a/micro-tomcat-with-jersey/src/test/java/app/filter/com/oath/micro/server/FilterStatusResource.java b/micro-tomcat-with-jersey/src/test/java/app/filter/com/oath/micro/server/FilterStatusResource.java new file mode 100644 index 000000000..c7166c216 --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/filter/com/oath/micro/server/FilterStatusResource.java @@ -0,0 +1,36 @@ +package app.filter.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.RestResource; + +@Component +@Scope(value=ConfigurableBeanFactory.SCOPE_PROTOTYPE) +@Path("/status") +public class FilterStatusResource implements RestResource { + + @Autowired + private RequestScopeUserInfo info; + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + info.print(); + return "ok"; + } + @GET + @Produces("text/plain") + @Path("/ping2") + public String ping2() { + return "ok"; + } + +} \ No newline at end of file diff --git a/micro-tomcat-with-jersey/src/test/java/app/filter/com/oath/micro/server/RequestScopeUserInfo.java b/micro-tomcat-with-jersey/src/test/java/app/filter/com/oath/micro/server/RequestScopeUserInfo.java new file mode 100644 index 000000000..84c19c3f4 --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/filter/com/oath/micro/server/RequestScopeUserInfo.java @@ -0,0 +1,20 @@ +package app.filter.com.oath.micro.server; + +import javax.servlet.http.HttpServletRequest; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Scope; +import org.springframework.context.annotation.ScopedProxyMode; +import org.springframework.stereotype.Component; +import org.springframework.web.context.WebApplicationContext; + +@Component +@Scope(value=WebApplicationContext.SCOPE_REQUEST,proxyMode=ScopedProxyMode.TARGET_CLASS) +public class RequestScopeUserInfo { + @Autowired + private HttpServletRequest request; + + public void print(){ + System.out.println(request.getAttribute("oc.info")); + } +} diff --git a/micro-tomcat-with-jersey/src/test/java/app/listeners/com/aol/micro/server/AutodiscoveredListener.java b/micro-tomcat-with-jersey/src/test/java/app/listeners/com/aol/micro/server/AutodiscoveredListener.java deleted file mode 100644 index bff7cbdc8..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/listeners/com/aol/micro/server/AutodiscoveredListener.java +++ /dev/null @@ -1,35 +0,0 @@ -package app.listeners.com.aol.micro.server; - -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; - -import lombok.Getter; - -import org.springframework.stereotype.Component; - -@Component -public class AutodiscoveredListener implements ServletContextListener { - - @Getter - private static volatile int called= 0; - - @Override - public void contextInitialized(ServletContextEvent sce) { - called ++; - - } - - @Override - public void contextDestroyed(ServletContextEvent sce) { - - - } - - - - - - - - -} \ No newline at end of file diff --git a/micro-tomcat-with-jersey/src/test/java/app/listeners/com/aol/micro/server/ConfiguredListener.java b/micro-tomcat-with-jersey/src/test/java/app/listeners/com/aol/micro/server/ConfiguredListener.java deleted file mode 100644 index d15dcb76e..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/listeners/com/aol/micro/server/ConfiguredListener.java +++ /dev/null @@ -1,25 +0,0 @@ -package app.listeners.com.aol.micro.server; - -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; - -import lombok.Getter; - -public class ConfiguredListener implements ServletContextListener { - - @Getter - private static volatile int called= 0; - - @Override - public void contextInitialized(ServletContextEvent sce) { - called ++; - - } - - @Override - public void contextDestroyed(ServletContextEvent sce) { - - - } - -} \ No newline at end of file diff --git a/micro-tomcat-with-jersey/src/test/java/app/listeners/com/aol/micro/server/ListenerRunnerTest.java b/micro-tomcat-with-jersey/src/test/java/app/listeners/com/aol/micro/server/ListenerRunnerTest.java deleted file mode 100644 index 4f8d7ab69..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/listeners/com/aol/micro/server/ListenerRunnerTest.java +++ /dev/null @@ -1,55 +0,0 @@ -package app.listeners.com.aol.micro.server; - - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.ExecutionException; - -import javax.servlet.ServletContextListener; - - - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.testing.RestAgent; - - -@Microserver -public class ListenerRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer(){ - List listeners = Arrays.asList(new ConfiguredListener()); - server = new MicroserverApp( ListenerRunnerTest.class, ConfigurableModule.builder().context("listener-app").listeners(listeners ).build()); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void testListeners() throws InterruptedException, ExecutionException{ - - assertThat(AutodiscoveredListener.getCalled(),is(1)); - assertThat(ConfiguredListener.getCalled(),is(1)); - } - - - - - -} diff --git a/micro-tomcat-with-jersey/src/test/java/app/listeners/com/oath/micro/server/AutodiscoveredListener.java b/micro-tomcat-with-jersey/src/test/java/app/listeners/com/oath/micro/server/AutodiscoveredListener.java new file mode 100644 index 000000000..a3dfdff21 --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/listeners/com/oath/micro/server/AutodiscoveredListener.java @@ -0,0 +1,35 @@ +package app.listeners.com.oath.micro.server; + +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; + +import lombok.Getter; + +import org.springframework.stereotype.Component; + +@Component +public class AutodiscoveredListener implements ServletContextListener { + + @Getter + private static volatile int called= 0; + + @Override + public void contextInitialized(ServletContextEvent sce) { + called ++; + + } + + @Override + public void contextDestroyed(ServletContextEvent sce) { + + + } + + + + + + + + +} \ No newline at end of file diff --git a/micro-tomcat-with-jersey/src/test/java/app/listeners/com/oath/micro/server/ConfiguredListener.java b/micro-tomcat-with-jersey/src/test/java/app/listeners/com/oath/micro/server/ConfiguredListener.java new file mode 100644 index 000000000..86a7cd34b --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/listeners/com/oath/micro/server/ConfiguredListener.java @@ -0,0 +1,25 @@ +package app.listeners.com.oath.micro.server; + +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; + +import lombok.Getter; + +public class ConfiguredListener implements ServletContextListener { + + @Getter + private static volatile int called= 0; + + @Override + public void contextInitialized(ServletContextEvent sce) { + called ++; + + } + + @Override + public void contextDestroyed(ServletContextEvent sce) { + + + } + +} \ No newline at end of file diff --git a/micro-tomcat-with-jersey/src/test/java/app/listeners/com/oath/micro/server/ListenerRunnerTest.java b/micro-tomcat-with-jersey/src/test/java/app/listeners/com/oath/micro/server/ListenerRunnerTest.java new file mode 100644 index 000000000..fa0222a76 --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/listeners/com/oath/micro/server/ListenerRunnerTest.java @@ -0,0 +1,55 @@ +package app.listeners.com.oath.micro.server; + + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.ExecutionException; + +import javax.servlet.ServletContextListener; + + + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.module.ConfigurableModule; +import com.oath.micro.server.testing.RestAgent; + + +@Microserver +public class ListenerRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer(){ + List listeners = Arrays.asList(new ConfiguredListener()); + server = new MicroserverApp( ListenerRunnerTest.class, ConfigurableModule.builder().context("listener-app").listeners(listeners ).build()); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void testListeners() throws InterruptedException, ExecutionException{ + + assertThat(AutodiscoveredListener.getCalled(),is(1)); + assertThat(ConfiguredListener.getCalled(),is(1)); + } + + + + + +} diff --git a/micro-tomcat-with-jersey/src/test/java/app/minimal/com/aol/micro/server/MinimalClassTest.java b/micro-tomcat-with-jersey/src/test/java/app/minimal/com/aol/micro/server/MinimalClassTest.java deleted file mode 100644 index 7462ab655..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/minimal/com/aol/micro/server/MinimalClassTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package app.minimal.com.aol.micro.server; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.auto.discovery.RestResource; -import com.aol.micro.server.testing.RestAgent; - -@Rest -@Path("/single") -public class MinimalClassTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer(){ - - server = new MicroserverApp(()-> "minimal-app"); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - Thread.sleep(500); - - assertThat(rest.get("http://localhost:8080/minimal-app/single/ping"),is("ok")); - - } - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "ok"; - } - - -} \ No newline at end of file diff --git a/micro-tomcat-with-jersey/src/test/java/app/minimal/com/oath/micro/server/MinimalClassTest.java b/micro-tomcat-with-jersey/src/test/java/app/minimal/com/oath/micro/server/MinimalClassTest.java new file mode 100644 index 000000000..9d17b99b6 --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/minimal/com/oath/micro/server/MinimalClassTest.java @@ -0,0 +1,57 @@ +package app.minimal.com.oath.micro.server; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.auto.discovery.Rest; +import com.oath.micro.server.testing.RestAgent; + +@Rest +@Path("/single") +public class MinimalClassTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer(){ + + server = new MicroserverApp(()-> "minimal-app"); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + Thread.sleep(500); + + assertThat(rest.get("http://localhost:8080/minimal-app/single/ping"),is("ok")); + + } + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "ok"; + } + + +} \ No newline at end of file diff --git a/micro-tomcat-with-jersey/src/test/java/app/noanno/com/aol/micro/server/copy/NoAnnoRunnerTest.java b/micro-tomcat-with-jersey/src/test/java/app/noanno/com/aol/micro/server/copy/NoAnnoRunnerTest.java deleted file mode 100644 index 92abed060..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/noanno/com/aol/micro/server/copy/NoAnnoRunnerTest.java +++ /dev/null @@ -1,49 +0,0 @@ -package app.noanno.com.aol.micro.server.copy; - - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.testing.RestAgent; - - -public class NoAnnoRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer() throws InterruptedException{ - - server = new MicroserverApp(()-> "simple-app"); - Thread.sleep(1000); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - - - assertThat(rest.get("http://localhost:8080/simple-app/status/ping"),is("ok")); - - - } - - - -} diff --git a/micro-tomcat-with-jersey/src/test/java/app/noanno/com/aol/micro/server/copy/NoAnnoStatusResource.java b/micro-tomcat-with-jersey/src/test/java/app/noanno/com/aol/micro/server/copy/NoAnnoStatusResource.java deleted file mode 100644 index 8a3f5efaa..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/noanno/com/aol/micro/server/copy/NoAnnoStatusResource.java +++ /dev/null @@ -1,24 +0,0 @@ -package app.noanno.com.aol.micro.server.copy; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import com.aol.micro.server.auto.discovery.Rest; - -@Rest -@Path("/status") -public class NoAnnoStatusResource { - - - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - - return "ok"; - } - - -} \ No newline at end of file diff --git a/micro-tomcat-with-jersey/src/test/java/app/noanno/com/aol/micro/server/copy/SimpleApp.java b/micro-tomcat-with-jersey/src/test/java/app/noanno/com/aol/micro/server/copy/SimpleApp.java deleted file mode 100644 index 5fb7e2ca3..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/noanno/com/aol/micro/server/copy/SimpleApp.java +++ /dev/null @@ -1,12 +0,0 @@ -package app.noanno.com.aol.micro.server.copy; - -import com.aol.micro.server.MicroserverApp; - -public class SimpleApp { - - public static void main(String[] args){ - new MicroserverApp(()-> "simple-app").run(); - } - - -} diff --git a/micro-tomcat-with-jersey/src/test/java/app/noanno/com/oath/micro/server/copy/NoAnnoRunnerTest.java b/micro-tomcat-with-jersey/src/test/java/app/noanno/com/oath/micro/server/copy/NoAnnoRunnerTest.java new file mode 100644 index 000000000..b476e2791 --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/noanno/com/oath/micro/server/copy/NoAnnoRunnerTest.java @@ -0,0 +1,48 @@ +package app.noanno.com.oath.micro.server.copy; + + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.testing.RestAgent; + + +public class NoAnnoRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer() throws InterruptedException{ + + server = new MicroserverApp(()-> "simple-app"); + Thread.sleep(1000); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + + + assertThat(rest.get("http://localhost:8080/simple-app/status/ping"),is("ok")); + + + } + + + +} diff --git a/micro-tomcat-with-jersey/src/test/java/app/noanno/com/oath/micro/server/copy/NoAnnoStatusResource.java b/micro-tomcat-with-jersey/src/test/java/app/noanno/com/oath/micro/server/copy/NoAnnoStatusResource.java new file mode 100644 index 000000000..11a42968e --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/noanno/com/oath/micro/server/copy/NoAnnoStatusResource.java @@ -0,0 +1,24 @@ +package app.noanno.com.oath.micro.server.copy; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import com.oath.micro.server.auto.discovery.Rest; + +@Rest +@Path("/status") +public class NoAnnoStatusResource { + + + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + + return "ok"; + } + + +} \ No newline at end of file diff --git a/micro-tomcat-with-jersey/src/test/java/app/noanno/com/oath/micro/server/copy/SimpleApp.java b/micro-tomcat-with-jersey/src/test/java/app/noanno/com/oath/micro/server/copy/SimpleApp.java new file mode 100644 index 000000000..646004a31 --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/noanno/com/oath/micro/server/copy/SimpleApp.java @@ -0,0 +1,12 @@ +package app.noanno.com.oath.micro.server.copy; + +import com.oath.micro.server.MicroserverApp; + +public class SimpleApp { + + public static void main(String[] args){ + new MicroserverApp(()-> "simple-app").run(); + } + + +} diff --git a/micro-tomcat-with-jersey/src/test/java/app/properties/instance/com/aol/micro/server/ServicePropertiesTest.java b/micro-tomcat-with-jersey/src/test/java/app/properties/instance/com/aol/micro/server/ServicePropertiesTest.java deleted file mode 100644 index 66ae36c54..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/properties/instance/com/aol/micro/server/ServicePropertiesTest.java +++ /dev/null @@ -1,66 +0,0 @@ -package app.properties.instance.com.aol.micro.server; - -import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.springframework.beans.factory.annotation.Value; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.testing.RestAgent; - -@Rest -@Path("/single") -@Microserver(instancePropertiesName="myinstance.properties") -public class ServicePropertiesTest { - - RestAgent rest = new RestAgent(); - - @Value("${type.property}") - private String type; - MicroserverApp server; - @Before - public void startServer() throws InterruptedException{ - - server = new MicroserverApp(()-> "minimal-app"); - Thread.sleep(1000); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - - - assertThat(rest.get("http://localhost:8080/minimal-app/single/ping"),is("ok")); - - - - } - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - assertThat(type,equalTo("instance")); - return "ok"; - } - - -} \ No newline at end of file diff --git a/micro-tomcat-with-jersey/src/test/java/app/properties/instance/com/oath/micro/server/ServicePropertiesTest.java b/micro-tomcat-with-jersey/src/test/java/app/properties/instance/com/oath/micro/server/ServicePropertiesTest.java new file mode 100644 index 000000000..0b84e4db2 --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/properties/instance/com/oath/micro/server/ServicePropertiesTest.java @@ -0,0 +1,66 @@ +package app.properties.instance.com.oath.micro.server; + +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Value; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.auto.discovery.Rest; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.testing.RestAgent; + +@Rest +@Path("/single") +@Microserver(instancePropertiesName="myinstance.properties") +public class ServicePropertiesTest { + + RestAgent rest = new RestAgent(); + + @Value("${type.property}") + private String type; + MicroserverApp server; + @Before + public void startServer() throws InterruptedException{ + + server = new MicroserverApp(()-> "minimal-app"); + Thread.sleep(1000); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + + + assertThat(rest.get("http://localhost:8080/minimal-app/single/ping"),is("ok")); + + + + } + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + assertThat(type,equalTo("instance")); + return "ok"; + } + + +} \ No newline at end of file diff --git a/micro-tomcat-with-jersey/src/test/java/app/properties/service/com/aol/micro/server/ServicePropertiesTest.java b/micro-tomcat-with-jersey/src/test/java/app/properties/service/com/aol/micro/server/ServicePropertiesTest.java deleted file mode 100644 index de9241729..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/properties/service/com/aol/micro/server/ServicePropertiesTest.java +++ /dev/null @@ -1,66 +0,0 @@ -package app.properties.service.com.aol.micro.server; - -import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.springframework.beans.factory.annotation.Value; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.testing.RestAgent; - -@Rest -@Path("/single") -@Microserver(serviceTypePropertiesName="myservice.properties") -public class ServicePropertiesTest { - - RestAgent rest = new RestAgent(); - - @Value("${type.property}") - private String type; - MicroserverApp server; - @Before - public void startServer() throws InterruptedException{ - - server = new MicroserverApp(()-> "minimal-app"); - Thread.sleep(1000); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - - - assertThat(rest.get("http://localhost:8080/minimal-app/single/ping"),is("ok")); - - - - } - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - assertThat(type,equalTo("set")); - return "ok"; - } - - -} \ No newline at end of file diff --git a/micro-tomcat-with-jersey/src/test/java/app/properties/service/com/oath/micro/server/ServicePropertiesTest.java b/micro-tomcat-with-jersey/src/test/java/app/properties/service/com/oath/micro/server/ServicePropertiesTest.java new file mode 100644 index 000000000..876326418 --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/properties/service/com/oath/micro/server/ServicePropertiesTest.java @@ -0,0 +1,66 @@ +package app.properties.service.com.oath.micro.server; + +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Value; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.auto.discovery.Rest; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.testing.RestAgent; + +@Rest +@Path("/single") +@Microserver(serviceTypePropertiesName="myservice.properties") +public class ServicePropertiesTest { + + RestAgent rest = new RestAgent(); + + @Value("${type.property}") + private String type; + MicroserverApp server; + @Before + public void startServer() throws InterruptedException{ + + server = new MicroserverApp(()-> "minimal-app"); + Thread.sleep(1000); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + + + assertThat(rest.get("http://localhost:8080/minimal-app/single/ping"),is("ok")); + + + + } + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + assertThat(type,equalTo("set")); + return "ok"; + } + + +} \ No newline at end of file diff --git a/micro-tomcat-with-jersey/src/test/java/app/servlet/com/aol/micro/server/AppRunnerLocalMain.java b/micro-tomcat-with-jersey/src/test/java/app/servlet/com/aol/micro/server/AppRunnerLocalMain.java deleted file mode 100644 index b447491a1..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/servlet/com/aol/micro/server/AppRunnerLocalMain.java +++ /dev/null @@ -1,20 +0,0 @@ -package app.servlet.com.aol.micro.server; - - -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; - -import com.aol.micro.server.MicroserverApp; - -@Configuration -@ComponentScan(basePackages = { "app.servlet.com.aol.micro.server" }) -public class AppRunnerLocalMain { - - - public static void main(String[] args) throws InterruptedException { - - new MicroserverApp( AppRunnerLocalMain.class, () -> "test-app") - .run(); - } - -} diff --git a/micro-tomcat-with-jersey/src/test/java/app/servlet/com/aol/micro/server/AutodiscoveredServlet.java b/micro-tomcat-with-jersey/src/test/java/app/servlet/com/aol/micro/server/AutodiscoveredServlet.java deleted file mode 100644 index 3e64043bf..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/servlet/com/aol/micro/server/AutodiscoveredServlet.java +++ /dev/null @@ -1,30 +0,0 @@ -package app.servlet.com.aol.micro.server; - -import java.io.IOException; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.AutoServletConfiguration; - -@Component -public class AutodiscoveredServlet extends HttpServlet implements AutoServletConfiguration { - - @Override - public String[] getMapping() { - return new String[] { "/servlet" }; - } - - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) - throws ServletException, IOException { - - resp.setContentType("text/html"); - resp.getWriter().write("hello world"); - } - -} diff --git a/micro-tomcat-with-jersey/src/test/java/app/servlet/com/aol/micro/server/ConfiguredServlet.java b/micro-tomcat-with-jersey/src/test/java/app/servlet/com/aol/micro/server/ConfiguredServlet.java deleted file mode 100644 index 92577a92e..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/servlet/com/aol/micro/server/ConfiguredServlet.java +++ /dev/null @@ -1,24 +0,0 @@ -package app.servlet.com.aol.micro.server; - -import java.io.IOException; - -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -public class ConfiguredServlet extends HttpServlet { - - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) - throws ServletException, IOException { - resp.setContentType("text/html"); - resp.getWriter().write("configured servlet"); - } - - - -} diff --git a/micro-tomcat-with-jersey/src/test/java/app/servlet/com/aol/micro/server/ServletRunnerTest.java b/micro-tomcat-with-jersey/src/test/java/app/servlet/com/aol/micro/server/ServletRunnerTest.java deleted file mode 100644 index e821da8b6..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/servlet/com/aol/micro/server/ServletRunnerTest.java +++ /dev/null @@ -1,65 +0,0 @@ -package app.servlet.com.aol.micro.server; - - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.ExecutionException; - -import javax.servlet.Servlet; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.testing.RestAgent; - -public class ServletRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer() throws InterruptedException{ - Map servlets = new HashMap<>(); - servlets.put("/configured", new ConfiguredServlet()); - server = new MicroserverApp( AppRunnerLocalMain.class, ConfigurableModule.builder().context("test-app").servlets(servlets ).build()); - Thread.sleep(1000); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - assertThat(rest.get("http://localhost:8080/test-app/servlet/ping"),is("ok")); - - } - - @Test - public void autoDiscoveredServletTest() throws InterruptedException, ExecutionException{ - - - assertThat(rest.get("http://localhost:8080/servlet"),is("hello world")); - - } - - @Test - public void configuredServletTest() throws InterruptedException, ExecutionException{ - - - assertThat(rest.get("http://localhost:8080/configured"),is("configured servlet")); - - } - - -} diff --git a/micro-tomcat-with-jersey/src/test/java/app/servlet/com/aol/micro/server/ServletStatusResource.java b/micro-tomcat-with-jersey/src/test/java/app/servlet/com/aol/micro/server/ServletStatusResource.java deleted file mode 100644 index 890a64679..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/servlet/com/aol/micro/server/ServletStatusResource.java +++ /dev/null @@ -1,22 +0,0 @@ -package app.servlet.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.RestResource; - -@Component -@Path("/servlet") -public class ServletStatusResource implements RestResource { - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "ok"; - } - -} \ No newline at end of file diff --git a/micro-tomcat-with-jersey/src/test/java/app/servlet/com/oath/micro/server/AppRunnerLocalMain.java b/micro-tomcat-with-jersey/src/test/java/app/servlet/com/oath/micro/server/AppRunnerLocalMain.java new file mode 100644 index 000000000..217fc92d4 --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/servlet/com/oath/micro/server/AppRunnerLocalMain.java @@ -0,0 +1,20 @@ +package app.servlet.com.oath.micro.server; + + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +import com.oath.micro.server.MicroserverApp; + +@Configuration +@ComponentScan(basePackages = { "app.servlet.com.oath.micro.server" }) +public class AppRunnerLocalMain { + + + public static void main(String[] args) throws InterruptedException { + + new MicroserverApp( AppRunnerLocalMain.class, () -> "test-app") + .run(); + } + +} diff --git a/micro-tomcat-with-jersey/src/test/java/app/servlet/com/oath/micro/server/AutodiscoveredServlet.java b/micro-tomcat-with-jersey/src/test/java/app/servlet/com/oath/micro/server/AutodiscoveredServlet.java new file mode 100644 index 000000000..66cbfd59c --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/servlet/com/oath/micro/server/AutodiscoveredServlet.java @@ -0,0 +1,30 @@ +package app.servlet.com.oath.micro.server; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.AutoServletConfiguration; + +@Component +public class AutodiscoveredServlet extends HttpServlet implements AutoServletConfiguration { + + @Override + public String[] getMapping() { + return new String[] { "/servlet" }; + } + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + + resp.setContentType("text/html"); + resp.getWriter().write("hello world"); + } + +} diff --git a/micro-tomcat-with-jersey/src/test/java/app/servlet/com/oath/micro/server/ConfiguredServlet.java b/micro-tomcat-with-jersey/src/test/java/app/servlet/com/oath/micro/server/ConfiguredServlet.java new file mode 100644 index 000000000..65de82291 --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/servlet/com/oath/micro/server/ConfiguredServlet.java @@ -0,0 +1,21 @@ +package app.servlet.com.oath.micro.server; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class ConfiguredServlet extends HttpServlet { + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + resp.setContentType("text/html"); + resp.getWriter().write("configured servlet"); + } + + + +} diff --git a/micro-tomcat-with-jersey/src/test/java/app/servlet/com/oath/micro/server/ServletRunnerTest.java b/micro-tomcat-with-jersey/src/test/java/app/servlet/com/oath/micro/server/ServletRunnerTest.java new file mode 100644 index 000000000..19054192a --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/servlet/com/oath/micro/server/ServletRunnerTest.java @@ -0,0 +1,65 @@ +package app.servlet.com.oath.micro.server; + + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ExecutionException; + +import javax.servlet.Servlet; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.module.ConfigurableModule; +import com.oath.micro.server.testing.RestAgent; + +public class ServletRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer() throws InterruptedException{ + Map servlets = new HashMap<>(); + servlets.put("/configured", new ConfiguredServlet()); + server = new MicroserverApp( AppRunnerLocalMain.class, ConfigurableModule.builder().context("test-app").servlets(servlets ).build()); + Thread.sleep(1000); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + assertThat(rest.get("http://localhost:8080/test-app/servlet/ping"),is("ok")); + + } + + @Test + public void autoDiscoveredServletTest() throws InterruptedException, ExecutionException{ + + + assertThat(rest.get("http://localhost:8080/servlet"),is("hello world")); + + } + + @Test + public void configuredServletTest() throws InterruptedException, ExecutionException{ + + + assertThat(rest.get("http://localhost:8080/configured"),is("configured servlet")); + + } + + +} diff --git a/micro-tomcat-with-jersey/src/test/java/app/servlet/com/oath/micro/server/ServletStatusResource.java b/micro-tomcat-with-jersey/src/test/java/app/servlet/com/oath/micro/server/ServletStatusResource.java new file mode 100644 index 000000000..6d86eeb84 --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/servlet/com/oath/micro/server/ServletStatusResource.java @@ -0,0 +1,22 @@ +package app.servlet.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.RestResource; + +@Component +@Path("/servlet") +public class ServletStatusResource implements RestResource { + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "ok"; + } + +} \ No newline at end of file diff --git a/micro-tomcat-with-jersey/src/test/java/app/simple/com/aol/micro/server/SimpleApp.java b/micro-tomcat-with-jersey/src/test/java/app/simple/com/aol/micro/server/SimpleApp.java deleted file mode 100644 index 700a2c778..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/simple/com/aol/micro/server/SimpleApp.java +++ /dev/null @@ -1,18 +0,0 @@ -package app.simple.com.aol.micro.server; - -import java.util.Arrays; - -import org.glassfish.jersey.media.multipart.MultiPartFeature; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.module.ConfigurableModule; - -public class SimpleApp { - - public static void main(String[] args){ - - new MicroserverApp(()-> "simple-app").run(); - } - - -} diff --git a/micro-tomcat-with-jersey/src/test/java/app/simple/com/aol/micro/server/SimpleRunnerTest.java b/micro-tomcat-with-jersey/src/test/java/app/simple/com/aol/micro/server/SimpleRunnerTest.java deleted file mode 100644 index 57bc0e1ef..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/simple/com/aol/micro/server/SimpleRunnerTest.java +++ /dev/null @@ -1,55 +0,0 @@ -package app.simple.com.aol.micro.server; - - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.Arrays; -import java.util.concurrent.ExecutionException; - -import org.glassfish.jersey.media.multipart.MultiPartFeature; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.testing.RestAgent; - -@Microserver -public class SimpleRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer() throws InterruptedException{ - server = new MicroserverApp(ConfigurableModule - .builder() - .context("simple-app") - .defaultResources(Arrays.asList(MultiPartFeature.class)) - .build()); - Thread.sleep(1000); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - - - assertThat(rest.get("http://localhost:8080/simple-app/status/ping"),is("ok")); - - - } - - - -} diff --git a/micro-tomcat-with-jersey/src/test/java/app/simple/com/aol/micro/server/SimpleStatusResource.java b/micro-tomcat-with-jersey/src/test/java/app/simple/com/aol/micro/server/SimpleStatusResource.java deleted file mode 100644 index 17e6c3e45..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/simple/com/aol/micro/server/SimpleStatusResource.java +++ /dev/null @@ -1,39 +0,0 @@ -package app.simple.com.aol.micro.server; - -import java.io.InputStream; - -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; - -import org.glassfish.jersey.media.multipart.FormDataContentDisposition; -import org.glassfish.jersey.media.multipart.FormDataParam; - -import com.aol.micro.server.auto.discovery.Rest; - -@Rest -@Path("/status") -public class SimpleStatusResource { - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - - return "ok"; - } - - @POST - @Consumes(MediaType.MULTIPART_FORM_DATA) - @Produces(MediaType.TEXT_PLAIN) - @Path("/file") - public String create( - @FormDataParam("file") InputStream fileInputStream, - @FormDataParam("file") FormDataContentDisposition contentDispositionHeader) { - - return "done"; - } -} \ No newline at end of file diff --git a/micro-tomcat-with-jersey/src/test/java/app/simple/com/oath/micro/server/SimpleApp.java b/micro-tomcat-with-jersey/src/test/java/app/simple/com/oath/micro/server/SimpleApp.java new file mode 100644 index 000000000..e82a92291 --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/simple/com/oath/micro/server/SimpleApp.java @@ -0,0 +1,13 @@ +package app.simple.com.oath.micro.server; + +import com.oath.micro.server.MicroserverApp; + +public class SimpleApp { + + public static void main(String[] args){ + + new MicroserverApp(()-> "simple-app").run(); + } + + +} diff --git a/micro-tomcat-with-jersey/src/test/java/app/simple/com/oath/micro/server/SimpleRunnerTest.java b/micro-tomcat-with-jersey/src/test/java/app/simple/com/oath/micro/server/SimpleRunnerTest.java new file mode 100644 index 000000000..504b5199e --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/simple/com/oath/micro/server/SimpleRunnerTest.java @@ -0,0 +1,55 @@ +package app.simple.com.oath.micro.server; + + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.Arrays; +import java.util.concurrent.ExecutionException; + +import org.glassfish.jersey.media.multipart.MultiPartFeature; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.module.ConfigurableModule; +import com.oath.micro.server.testing.RestAgent; + +@Microserver +public class SimpleRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer() throws InterruptedException{ + server = new MicroserverApp(ConfigurableModule + .builder() + .context("simple-app") + .defaultResources(Arrays.asList(MultiPartFeature.class)) + .build()); + Thread.sleep(1000); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + + + assertThat(rest.get("http://localhost:8080/simple-app/status/ping"),is("ok")); + + + } + + + +} diff --git a/micro-tomcat-with-jersey/src/test/java/app/simple/com/oath/micro/server/SimpleStatusResource.java b/micro-tomcat-with-jersey/src/test/java/app/simple/com/oath/micro/server/SimpleStatusResource.java new file mode 100644 index 000000000..2a894a8fc --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/simple/com/oath/micro/server/SimpleStatusResource.java @@ -0,0 +1,39 @@ +package app.simple.com.oath.micro.server; + +import java.io.InputStream; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +import org.glassfish.jersey.media.multipart.FormDataContentDisposition; +import org.glassfish.jersey.media.multipart.FormDataParam; + +import com.oath.micro.server.auto.discovery.Rest; + +@Rest +@Path("/status") +public class SimpleStatusResource { + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + + return "ok"; + } + + @POST + @Consumes(MediaType.MULTIPART_FORM_DATA) + @Produces(MediaType.TEXT_PLAIN) + @Path("/file") + public String create( + @FormDataParam("file") InputStream fileInputStream, + @FormDataParam("file") FormDataContentDisposition contentDispositionHeader) { + + return "done"; + } +} \ No newline at end of file diff --git a/micro-tomcat-with-jersey/src/test/java/app/single/com/aol/micro/server/SingleClassTest.java b/micro-tomcat-with-jersey/src/test/java/app/single/com/aol/micro/server/SingleClassTest.java deleted file mode 100644 index 4839e9fff..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/single/com/aol/micro/server/SingleClassTest.java +++ /dev/null @@ -1,59 +0,0 @@ -package app.single.com.aol.micro.server; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.RestResource; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.testing.RestAgent; - -@Microserver -@Path("/single") -public class SingleClassTest implements RestResource{ - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer() throws InterruptedException{ - - server = new MicroserverApp( SingleClassTest.class, ()-> "simple-app"); - Thread.sleep(1000); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - - - assertThat(rest.get("http://localhost:8080/simple-app/single/ping"),is("ok")); - - } - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "ok"; - } - - -} \ No newline at end of file diff --git a/micro-tomcat-with-jersey/src/test/java/app/single/com/oath/micro/server/SingleClassTest.java b/micro-tomcat-with-jersey/src/test/java/app/single/com/oath/micro/server/SingleClassTest.java new file mode 100644 index 000000000..324cf4dce --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/single/com/oath/micro/server/SingleClassTest.java @@ -0,0 +1,59 @@ +package app.single.com.oath.micro.server; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.auto.discovery.RestResource; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.testing.RestAgent; + +@Microserver +@Path("/single") +public class SingleClassTest implements RestResource{ + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer() throws InterruptedException{ + + server = new MicroserverApp( SingleClassTest.class, ()-> "simple-app"); + Thread.sleep(1000); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + + + assertThat(rest.get("http://localhost:8080/simple-app/single/ping"),is("ok")); + + } + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "ok"; + } + + +} \ No newline at end of file diff --git a/micro-tomcat-with-jersey/src/test/java/app/single/main/com/aol/micro/server/SingleClassApp.java b/micro-tomcat-with-jersey/src/test/java/app/single/main/com/aol/micro/server/SingleClassApp.java deleted file mode 100644 index aef7a170c..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/single/main/com/aol/micro/server/SingleClassApp.java +++ /dev/null @@ -1,24 +0,0 @@ -package app.single.main.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.Rest; - -@Rest -@Path("/status") -public class SingleClassApp { - - public static void main(String[] args){ - new MicroserverApp(()-> "simple-app").run(); - } - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "ok"; - } - -} diff --git a/micro-tomcat-with-jersey/src/test/java/app/single/main/com/oath/micro/server/SingleClassApp.java b/micro-tomcat-with-jersey/src/test/java/app/single/main/com/oath/micro/server/SingleClassApp.java new file mode 100644 index 000000000..2d7a71917 --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/single/main/com/oath/micro/server/SingleClassApp.java @@ -0,0 +1,24 @@ +package app.single.main.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.auto.discovery.Rest; + +@Rest +@Path("/status") +public class SingleClassApp { + + public static void main(String[] args){ + new MicroserverApp(()-> "simple-app").run(); + } + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "ok"; + } + +} diff --git a/micro-tomcat-with-jersey/src/test/java/app/single/serverconfig/com/aol/micro/server/SingleClassTest.java b/micro-tomcat-with-jersey/src/test/java/app/single/serverconfig/com/aol/micro/server/SingleClassTest.java deleted file mode 100644 index 5c0cb67b8..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/single/serverconfig/com/aol/micro/server/SingleClassTest.java +++ /dev/null @@ -1,65 +0,0 @@ -package app.single.serverconfig.com.aol.micro.server; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.*; - -import java.util.concurrent.ExecutionException; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.RestResource; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.testing.RestAgent; - - -@Path("/single") -public class SingleClassTest implements RestResource{ - - RestAgent rest = new RestAgent(); - - boolean called; - MicroserverApp server; - @Before - public void startServer() throws InterruptedException{ - called = false; - server = new MicroserverApp( ConfigurableModule.builder() - .context("hello") - .serverConfigManager(server->called=true) - .build()); - Thread.sleep(1000); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - - - assertThat(rest.get("http://localhost:8080/hello/single/ping"),is("ok")); - assertTrue(called); - - } - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "ok"; - } - - -} \ No newline at end of file diff --git a/micro-tomcat-with-jersey/src/test/java/app/single/serverconfig/com/oath/micro/server/SingleClassTest.java b/micro-tomcat-with-jersey/src/test/java/app/single/serverconfig/com/oath/micro/server/SingleClassTest.java new file mode 100644 index 000000000..6d0bc5d09 --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/single/serverconfig/com/oath/micro/server/SingleClassTest.java @@ -0,0 +1,64 @@ +package app.single.serverconfig.com.oath.micro.server; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.*; + +import java.util.concurrent.ExecutionException; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.auto.discovery.RestResource; +import com.oath.micro.server.module.ConfigurableModule; +import com.oath.micro.server.testing.RestAgent; + + +@Path("/single") +public class SingleClassTest implements RestResource{ + + RestAgent rest = new RestAgent(); + + boolean called; + MicroserverApp server; + @Before + public void startServer() throws InterruptedException{ + called = false; + server = new MicroserverApp( ConfigurableModule.builder() + .context("hello") + .serverConfigManager(server->called=true) + .build()); + Thread.sleep(1000); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + + + assertThat(rest.get("http://localhost:8080/hello/single/ping"),is("ok")); + assertTrue(called); + + } + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "ok"; + } + + +} \ No newline at end of file diff --git a/micro-tomcat-with-jersey/src/test/java/app/spring/com/aol/micro/server/MyBean.java b/micro-tomcat-with-jersey/src/test/java/app/spring/com/aol/micro/server/MyBean.java deleted file mode 100644 index 1f7a589ff..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/spring/com/aol/micro/server/MyBean.java +++ /dev/null @@ -1,12 +0,0 @@ -package app.spring.com.aol.micro.server; - -import javax.inject.Inject; - -import lombok.Getter; - -@Getter -public class MyBean { - - @Inject - private MyDependency injected; -} diff --git a/micro-tomcat-with-jersey/src/test/java/app/spring/com/aol/micro/server/MyDependency.java b/micro-tomcat-with-jersey/src/test/java/app/spring/com/aol/micro/server/MyDependency.java deleted file mode 100644 index 48d89e6c5..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/spring/com/aol/micro/server/MyDependency.java +++ /dev/null @@ -1,12 +0,0 @@ -package app.spring.com.aol.micro.server; - -import lombok.Getter; - -import org.springframework.stereotype.Component; - -@Component -@Getter -public class MyDependency { - - private String data = "hello world"; -} diff --git a/micro-tomcat-with-jersey/src/test/java/app/spring/com/aol/micro/server/SpringRunnerTest.java b/micro-tomcat-with-jersey/src/test/java/app/spring/com/aol/micro/server/SpringRunnerTest.java deleted file mode 100644 index 6f777ba02..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/spring/com/aol/micro/server/SpringRunnerTest.java +++ /dev/null @@ -1,55 +0,0 @@ -package app.spring.com.aol.micro.server; - - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.springframework.context.annotation.Bean; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.testing.RestAgent; -/**@Configuration -@ComponentScan(basePackages = { "app.spring.com.aol.micro.server" })**/ -@Microserver -public class SpringRunnerTest { - - RestAgent rest = new RestAgent(); - - @Bean - public MyBean mybean(){ - return new MyBean(); - } - - MicroserverApp server; - @Before - public void startServer() throws InterruptedException{ - - server = new MicroserverApp( SpringRunnerTest.class, ()-> "spring-app"); - Thread.sleep(1000); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void testAutoWiring() throws InterruptedException, ExecutionException{ - - assertThat(rest.get("http://localhost:8080/spring-app/spring/ping"),is("hello world")); - - } - - - - - -} diff --git a/micro-tomcat-with-jersey/src/test/java/app/spring/com/aol/micro/server/SpringStatusResource.java b/micro-tomcat-with-jersey/src/test/java/app/spring/com/aol/micro/server/SpringStatusResource.java deleted file mode 100644 index 331ac997e..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/spring/com/aol/micro/server/SpringStatusResource.java +++ /dev/null @@ -1,32 +0,0 @@ -package app.spring.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.RestResource; - -@Component -@Path("/spring") -public class SpringStatusResource implements RestResource { - - @Autowired - private MyBean mybean; - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return mybean.getInjected().getData(); - } - @GET - @Produces("text/plain") - @Path("/ping2") - public String ping2() { - return "ok"; - } - -} \ No newline at end of file diff --git a/micro-tomcat-with-jersey/src/test/java/app/spring/com/oath/micro/server/MyBean.java b/micro-tomcat-with-jersey/src/test/java/app/spring/com/oath/micro/server/MyBean.java new file mode 100644 index 000000000..328b7d185 --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/spring/com/oath/micro/server/MyBean.java @@ -0,0 +1,12 @@ +package app.spring.com.oath.micro.server; + +import javax.inject.Inject; + +import lombok.Getter; + +@Getter +public class MyBean { + + @Inject + private MyDependency injected; +} diff --git a/micro-tomcat-with-jersey/src/test/java/app/spring/com/oath/micro/server/MyDependency.java b/micro-tomcat-with-jersey/src/test/java/app/spring/com/oath/micro/server/MyDependency.java new file mode 100644 index 000000000..1ca23b15b --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/spring/com/oath/micro/server/MyDependency.java @@ -0,0 +1,12 @@ +package app.spring.com.oath.micro.server; + +import lombok.Getter; + +import org.springframework.stereotype.Component; + +@Component +@Getter +public class MyDependency { + + private String data = "hello world"; +} diff --git a/micro-tomcat-with-jersey/src/test/java/app/spring/com/oath/micro/server/SpringRunnerTest.java b/micro-tomcat-with-jersey/src/test/java/app/spring/com/oath/micro/server/SpringRunnerTest.java new file mode 100644 index 000000000..8fb684d67 --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/spring/com/oath/micro/server/SpringRunnerTest.java @@ -0,0 +1,55 @@ +package app.spring.com.oath.micro.server; + + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.springframework.context.annotation.Bean; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.testing.RestAgent; +/**@Configuration +@ComponentScan(basePackages = { "app.spring.com.oath.micro.server" })**/ +@Microserver +public class SpringRunnerTest { + + RestAgent rest = new RestAgent(); + + @Bean + public MyBean mybean(){ + return new MyBean(); + } + + MicroserverApp server; + @Before + public void startServer() throws InterruptedException{ + + server = new MicroserverApp( SpringRunnerTest.class, ()-> "spring-app"); + Thread.sleep(1000); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void testAutoWiring() throws InterruptedException, ExecutionException{ + + assertThat(rest.get("http://localhost:8080/spring-app/spring/ping"),is("hello world")); + + } + + + + + +} diff --git a/micro-tomcat-with-jersey/src/test/java/app/spring/com/oath/micro/server/SpringStatusResource.java b/micro-tomcat-with-jersey/src/test/java/app/spring/com/oath/micro/server/SpringStatusResource.java new file mode 100644 index 000000000..ae0c817de --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/spring/com/oath/micro/server/SpringStatusResource.java @@ -0,0 +1,32 @@ +package app.spring.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.RestResource; + +@Component +@Path("/spring") +public class SpringStatusResource implements RestResource { + + @Autowired + private MyBean mybean; + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return mybean.getInjected().getData(); + } + @GET + @Produces("text/plain") + @Path("/ping2") + public String ping2() { + return "ok"; + } + +} \ No newline at end of file diff --git a/micro-tomcat-with-jersey/src/test/java/app/validation/com/aol/micro/server/ImmutableEntity.java b/micro-tomcat-with-jersey/src/test/java/app/validation/com/aol/micro/server/ImmutableEntity.java deleted file mode 100644 index 5b454305d..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/validation/com/aol/micro/server/ImmutableEntity.java +++ /dev/null @@ -1,28 +0,0 @@ -package app.validation.com.aol.micro.server; - - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Builder; - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "") -@XmlRootElement(name = "immutable") -@Getter -@AllArgsConstructor -@Builder -public class ImmutableEntity { - - private final String value; - - - public ImmutableEntity() { - this(null); - } - -} diff --git a/micro-tomcat-with-jersey/src/test/java/app/validation/com/aol/micro/server/ValidationAppResource.java b/micro-tomcat-with-jersey/src/test/java/app/validation/com/aol/micro/server/ValidationAppResource.java deleted file mode 100644 index 880c619e8..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/validation/com/aol/micro/server/ValidationAppResource.java +++ /dev/null @@ -1,23 +0,0 @@ -package app.validation.com.aol.micro.server; - -import javax.validation.constraints.NotNull; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.RestResource; -@Component -@Path("/status") -public class ValidationAppResource implements RestResource { - - @POST - @Produces("application/json") - @Path("/ping") - public ImmutableEntity ping( @NotNull ImmutableEntity entity) { - return entity; - } - - -} diff --git a/micro-tomcat-with-jersey/src/test/java/app/validation/com/aol/micro/server/ValidationAppTest.java b/micro-tomcat-with-jersey/src/test/java/app/validation/com/aol/micro/server/ValidationAppTest.java deleted file mode 100644 index e7bf73536..000000000 --- a/micro-tomcat-with-jersey/src/test/java/app/validation/com/aol/micro/server/ValidationAppTest.java +++ /dev/null @@ -1,75 +0,0 @@ -package app.validation.com.aol.micro.server; - -import java.util.concurrent.ExecutionException; - -import javax.ws.rs.BadRequestException; - -import com.oath.cyclops.types.futurestream.SimpleReactStream; -import cyclops.async.SimpleReact; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.testing.RestAgent; - -//@Microserver(basePackages = { "app.guava.com.aol.micro.server" }) -public class ValidationAppTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - - ImmutableEntity entity; - - - SimpleReact simpleReact = new SimpleReact(); - SimpleReactStream stream; - - @Before - public void startServer() throws InterruptedException { - server = new MicroserverApp(() -> "guava-app"); - Thread.sleep(1000); - server.start(); - - - entity = ImmutableEntity.builder().value("value").build(); - - - } - - @After - public void stopServer() { - server.stop(); - } - - - @Test(expected=BadRequestException.class) - public void confirmError() throws InterruptedException, - ExecutionException { - - - //stream.block(); - - rest.post( - "http://localhost:8080/guava-app/status/ping", null, - ImmutableEntity.class); - - - } - @Test - public void confirmNoError() throws InterruptedException, - ExecutionException { - - //stream.block(); - rest.post( - "http://localhost:8080/guava-app/status/ping", entity, - ImmutableEntity.class); - - - } - - - -} diff --git a/micro-tomcat-with-jersey/src/test/java/app/validation/com/oath/micro/server/ImmutableEntity.java b/micro-tomcat-with-jersey/src/test/java/app/validation/com/oath/micro/server/ImmutableEntity.java new file mode 100644 index 000000000..19e8f5b26 --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/validation/com/oath/micro/server/ImmutableEntity.java @@ -0,0 +1,28 @@ +package app.validation.com.oath.micro.server; + + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Builder; + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "") +@XmlRootElement(name = "immutable") +@Getter +@AllArgsConstructor +@Builder +public class ImmutableEntity { + + private final String value; + + + public ImmutableEntity() { + this(null); + } + +} diff --git a/micro-tomcat-with-jersey/src/test/java/app/validation/com/oath/micro/server/ValidationAppResource.java b/micro-tomcat-with-jersey/src/test/java/app/validation/com/oath/micro/server/ValidationAppResource.java new file mode 100644 index 000000000..7a8d0c325 --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/validation/com/oath/micro/server/ValidationAppResource.java @@ -0,0 +1,23 @@ +package app.validation.com.oath.micro.server; + +import javax.validation.constraints.NotNull; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.RestResource; +@Component +@Path("/status") +public class ValidationAppResource implements RestResource { + + @POST + @Produces("application/json") + @Path("/ping") + public ImmutableEntity ping( @NotNull ImmutableEntity entity) { + return entity; + } + + +} diff --git a/micro-tomcat-with-jersey/src/test/java/app/validation/com/oath/micro/server/ValidationAppTest.java b/micro-tomcat-with-jersey/src/test/java/app/validation/com/oath/micro/server/ValidationAppTest.java new file mode 100644 index 000000000..fcae5d3bf --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/app/validation/com/oath/micro/server/ValidationAppTest.java @@ -0,0 +1,75 @@ +package app.validation.com.oath.micro.server; + +import java.util.concurrent.ExecutionException; + +import javax.ws.rs.BadRequestException; + +import com.oath.cyclops.types.futurestream.SimpleReactStream; +import cyclops.async.SimpleReact; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.testing.RestAgent; + +//@Microserver(basePackages = { "app.guava.com.aol.micro.server" }) +public class ValidationAppTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + + ImmutableEntity entity; + + + SimpleReact simpleReact = new SimpleReact(); + SimpleReactStream stream; + + @Before + public void startServer() throws InterruptedException { + server = new MicroserverApp(() -> "guava-app"); + Thread.sleep(1000); + server.start(); + + + entity = ImmutableEntity.builder().value("value").build(); + + + } + + @After + public void stopServer() { + server.stop(); + } + + + @Test(expected=BadRequestException.class) + public void confirmError() throws InterruptedException, + ExecutionException { + + + //stream.block(); + + rest.post( + "http://localhost:8080/guava-app/status/ping", null, + ImmutableEntity.class); + + + } + @Test + public void confirmNoError() throws InterruptedException, + ExecutionException { + + //stream.block(); + rest.post( + "http://localhost:8080/guava-app/status/ping", entity, + ImmutableEntity.class); + + + } + + + +} diff --git a/micro-tomcat-with-jersey/src/test/java/com/aol/micro/server/testing/RestAgent.java b/micro-tomcat-with-jersey/src/test/java/com/aol/micro/server/testing/RestAgent.java deleted file mode 100644 index ce204f810..000000000 --- a/micro-tomcat-with-jersey/src/test/java/com/aol/micro/server/testing/RestAgent.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.aol.micro.server.testing; - -import java.util.List; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.Invocation.Builder; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; - -import com.aol.micro.server.rest.jackson.JacksonUtil; - -public class RestAgent { - - - public String getJson(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.get(String.class); - - } - - public String get(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.TEXT_PLAIN); - - return request.get(String.class); - - } - - public T post(String url, Object payload,Class type) { - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); - } - - -} diff --git a/micro-tomcat-with-jersey/src/test/java/com/oath/micro/server/testing/RestAgent.java b/micro-tomcat-with-jersey/src/test/java/com/oath/micro/server/testing/RestAgent.java new file mode 100644 index 000000000..b2b86303e --- /dev/null +++ b/micro-tomcat-with-jersey/src/test/java/com/oath/micro/server/testing/RestAgent.java @@ -0,0 +1,53 @@ +package com.oath.micro.server.testing; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.Invocation.Builder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; + +import com.oath.micro.server.rest.jackson.JacksonUtil; + +public class RestAgent { + + + public String getJson(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.get(String.class); + + } + + public String get(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.TEXT_PLAIN); + + return request.get(String.class); + + } + + public T post(String url, Object payload,Class type) { + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); + } + + +} diff --git a/micro-tomcat/src/main/java/com/aol/micro/server/servers/tomcat/SSLConfigurationBuilder.java b/micro-tomcat/src/main/java/com/aol/micro/server/servers/tomcat/SSLConfigurationBuilder.java deleted file mode 100644 index 74fb75f7e..000000000 --- a/micro-tomcat/src/main/java/com/aol/micro/server/servers/tomcat/SSLConfigurationBuilder.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.aol.micro.server.servers.tomcat; - - - -import org.apache.coyote.http11.AbstractHttp11JsseProtocol; - - -import com.aol.micro.server.config.SSLProperties; - -public class SSLConfigurationBuilder { - - - public void build(AbstractHttp11JsseProtocol protocol,SSLProperties sslProperties) { - protocol.setKeystoreFile(sslProperties.getKeyStoreFile()); // contains server keypair - protocol.setKeyPass(sslProperties.getKeyStorePass()); - sslProperties.getKeyStoreType().ifPresent(type->protocol.setKeystoreType(type)); - sslProperties.getKeyStoreProvider().ifPresent(provider->protocol.setKeystoreProvider(provider)); - - sslProperties.getTrustStoreFile().ifPresent(file->protocol.setTruststoreFile(file)); // contains client certificate - sslProperties.getTrustStorePass().ifPresent(pass->protocol.setTruststorePass(pass)); - - sslProperties.getTrustStoreType().ifPresent(type->protocol.setTruststoreType(type)); - sslProperties.getTrustStoreProvider().ifPresent(provider->protocol.setTruststoreProvider(provider)); - sslProperties.getClientAuth().ifPresent(auth->protocol.setClientAuth(auth)); - - protocol.setSSLEnabled(true); - sslProperties.getCiphers().ifPresent(ciphers->protocol.setCiphers(ciphers)); - sslProperties.getProtocol().ifPresent(pr->protocol.setSslProtocol(pr)); - - - } -} diff --git a/micro-tomcat/src/main/java/com/aol/micro/server/servers/tomcat/TomcatApplicationFactory.java b/micro-tomcat/src/main/java/com/aol/micro/server/servers/tomcat/TomcatApplicationFactory.java deleted file mode 100644 index de90670f0..000000000 --- a/micro-tomcat/src/main/java/com/aol/micro/server/servers/tomcat/TomcatApplicationFactory.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.aol.micro.server.servers.tomcat; - -import java.util.List; - -import com.oath.cyclops.types.persistent.PersistentList; -import lombok.AllArgsConstructor; - - -import org.springframework.context.ApplicationContext; - -import com.aol.micro.server.module.Environment; -import com.aol.micro.server.module.Module; -import com.aol.micro.server.module.ModuleDataExtractor; -import com.aol.micro.server.servers.ServerApplication; -import com.aol.micro.server.servers.ServerApplicationFactory; -import com.aol.micro.server.servers.model.AllData; -import com.aol.micro.server.servers.model.FilterData; -import com.aol.micro.server.servers.model.ServerData; -import com.aol.micro.server.servers.model.ServletData; - -@AllArgsConstructor -public class TomcatApplicationFactory implements ServerApplicationFactory { - - - - - public ServerApplication createApp(final Module module, final ApplicationContext rootContext) { - ModuleDataExtractor extractor = new ModuleDataExtractor(module); - PersistentList resources = extractor.getRestResources(rootContext); - - Environment environment = rootContext.getBean(Environment.class); - - environment.assureModule(module); - String fullRestResource = "/" + module.getContext() + "/*"; - - ServerData serverData = new ServerData(environment.getModuleBean(module).getPort(), - resources, - rootContext, fullRestResource, module); - List filterDataList = extractor.createFilteredDataList(serverData); - List servletDataList = extractor.createServletDataList(serverData); - - TomcatApplication app = new TomcatApplication( - new AllData(serverData, - filterDataList, - servletDataList, - module.getListeners(serverData), - module.getRequestListeners(serverData))); - return app; - } -} diff --git a/micro-tomcat/src/main/java/com/aol/micro/server/servers/tomcat/TomcatListener.java b/micro-tomcat/src/main/java/com/aol/micro/server/servers/tomcat/TomcatListener.java deleted file mode 100644 index 3dec34824..000000000 --- a/micro-tomcat/src/main/java/com/aol/micro/server/servers/tomcat/TomcatListener.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.aol.micro.server.servers.tomcat; - -import java.util.Set; - -import javax.servlet.ServletContainerInitializer; -import javax.servlet.ServletContext; -import javax.servlet.ServletContextListener; -import javax.servlet.ServletException; -import javax.servlet.ServletRequestListener; - - -import com.oath.cyclops.types.persistent.PersistentList; -import lombok.AllArgsConstructor; - -import com.aol.micro.server.servers.FilterConfigurer; -import com.aol.micro.server.servers.JaxRsServletConfigurer; -import com.aol.micro.server.servers.ServerThreadLocalVariables; -import com.aol.micro.server.servers.ServletConfigurer; -import com.aol.micro.server.servers.ServletContextListenerConfigurer; -import com.aol.micro.server.servers.model.FilterData; -import com.aol.micro.server.servers.model.ServerData; -import com.aol.micro.server.servers.model.ServletData; -@AllArgsConstructor -public class TomcatListener implements ServletContainerInitializer { - - - private final JaxRsServletConfigurer jaxRsConfigurer; - private final ServerData serverData; - - private final PersistentList filterData; - private final PersistentList servletData; - private final PersistentList servletContextListenerData; - private final PersistentList servletRequestListenerData; - - - @Override - public void onStartup(Set> classes, ServletContext webappContext) - throws ServletException { - try { - ServerThreadLocalVariables.getContext().set(serverData.getModule().getContext()); - - jaxRsConfigurer.addServlet(this.serverData,webappContext); - - new ServletConfigurer(serverData, servletData).addServlets(webappContext); - - new FilterConfigurer(serverData, this.filterData).addFilters(webappContext); - new ServletContextListenerConfigurer(serverData, servletContextListenerData, servletRequestListenerData).addListeners(webappContext); - - } - catch (Exception ex) { - - } - } - - - -} \ No newline at end of file diff --git a/micro-tomcat/src/main/java/com/aol/micro/server/servers/tomcat/plugin/TomcatPlugin.java b/micro-tomcat/src/main/java/com/aol/micro/server/servers/tomcat/plugin/TomcatPlugin.java deleted file mode 100644 index 99ed60b5b..000000000 --- a/micro-tomcat/src/main/java/com/aol/micro/server/servers/tomcat/plugin/TomcatPlugin.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.aol.micro.server.servers.tomcat.plugin; - -import java.util.Optional; - -import com.aol.micro.server.Plugin; -import com.aol.micro.server.servers.ServerApplicationFactory; -import com.aol.micro.server.servers.tomcat.TomcatApplicationFactory; - - -public class TomcatPlugin implements Plugin{ - - @Override - public Optional serverApplicationFactory(){ - return Optional.of(new TomcatApplicationFactory()); - } - - -} diff --git a/micro-tomcat/src/main/java/com/oath/micro/server/servers/tomcat/SSLConfigurationBuilder.java b/micro-tomcat/src/main/java/com/oath/micro/server/servers/tomcat/SSLConfigurationBuilder.java new file mode 100644 index 000000000..1ffa237f7 --- /dev/null +++ b/micro-tomcat/src/main/java/com/oath/micro/server/servers/tomcat/SSLConfigurationBuilder.java @@ -0,0 +1,32 @@ +package com.oath.micro.server.servers.tomcat; + + + +import org.apache.coyote.http11.AbstractHttp11JsseProtocol; + + +import com.oath.micro.server.config.SSLProperties; + +public class SSLConfigurationBuilder { + + + public void build(AbstractHttp11JsseProtocol protocol,SSLProperties sslProperties) { + protocol.setKeystoreFile(sslProperties.getKeyStoreFile()); // contains server keypair + protocol.setKeyPass(sslProperties.getKeyStorePass()); + sslProperties.getKeyStoreType().ifPresent(type->protocol.setKeystoreType(type)); + sslProperties.getKeyStoreProvider().ifPresent(provider->protocol.setKeystoreProvider(provider)); + + sslProperties.getTrustStoreFile().ifPresent(file->protocol.setTruststoreFile(file)); // contains client certificate + sslProperties.getTrustStorePass().ifPresent(pass->protocol.setTruststorePass(pass)); + + sslProperties.getTrustStoreType().ifPresent(type->protocol.setTruststoreType(type)); + sslProperties.getTrustStoreProvider().ifPresent(provider->protocol.setTruststoreProvider(provider)); + sslProperties.getClientAuth().ifPresent(auth->protocol.setClientAuth(auth)); + + protocol.setSSLEnabled(true); + sslProperties.getCiphers().ifPresent(ciphers->protocol.setCiphers(ciphers)); + sslProperties.getProtocol().ifPresent(pr->protocol.setSslProtocol(pr)); + + + } +} diff --git a/micro-tomcat/src/main/java/com/aol/micro/server/servers/tomcat/TomcatApplication.java b/micro-tomcat/src/main/java/com/oath/micro/server/servers/tomcat/TomcatApplication.java similarity index 90% rename from micro-tomcat/src/main/java/com/aol/micro/server/servers/tomcat/TomcatApplication.java rename to micro-tomcat/src/main/java/com/oath/micro/server/servers/tomcat/TomcatApplication.java index b80b462f4..1fef1bd23 100644 --- a/micro-tomcat/src/main/java/com/aol/micro/server/servers/tomcat/TomcatApplication.java +++ b/micro-tomcat/src/main/java/com/oath/micro/server/servers/tomcat/TomcatApplication.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.servers.tomcat; +package com.oath.micro.server.servers.tomcat; import java.io.File; import java.util.HashSet; @@ -27,16 +27,16 @@ import org.slf4j.LoggerFactory; -import com.aol.micro.server.InternalErrorCode; -import com.aol.micro.server.config.SSLProperties; -import com.aol.micro.server.module.WebServerProvider; -import com.aol.micro.server.servers.AccessLogLocationBean; -import com.aol.micro.server.servers.JaxRsServletConfigurer; -import com.aol.micro.server.servers.ServerApplication; -import com.aol.micro.server.servers.model.AllData; -import com.aol.micro.server.servers.model.FilterData; -import com.aol.micro.server.servers.model.ServerData; -import com.aol.micro.server.servers.model.ServletData; +import com.oath.micro.server.InternalErrorCode; +import com.oath.micro.server.config.SSLProperties; +import com.oath.micro.server.module.WebServerProvider; +import com.oath.micro.server.servers.AccessLogLocationBean; +import com.oath.micro.server.servers.JaxRsServletConfigurer; +import com.oath.micro.server.servers.ServerApplication; +import com.oath.micro.server.servers.model.AllData; +import com.oath.micro.server.servers.model.FilterData; +import com.oath.micro.server.servers.model.ServerData; +import com.oath.micro.server.servers.model.ServletData; @AllArgsConstructor(access = AccessLevel.PRIVATE) public class TomcatApplication implements ServerApplication { diff --git a/micro-tomcat/src/main/java/com/oath/micro/server/servers/tomcat/TomcatApplicationFactory.java b/micro-tomcat/src/main/java/com/oath/micro/server/servers/tomcat/TomcatApplicationFactory.java new file mode 100644 index 000000000..c0a17f216 --- /dev/null +++ b/micro-tomcat/src/main/java/com/oath/micro/server/servers/tomcat/TomcatApplicationFactory.java @@ -0,0 +1,50 @@ +package com.oath.micro.server.servers.tomcat; + +import java.util.List; + +import com.oath.cyclops.types.persistent.PersistentList; +import lombok.AllArgsConstructor; + + +import org.springframework.context.ApplicationContext; + +import com.oath.micro.server.module.Environment; +import com.oath.micro.server.module.Module; +import com.oath.micro.server.module.ModuleDataExtractor; +import com.oath.micro.server.servers.ServerApplication; +import com.oath.micro.server.servers.ServerApplicationFactory; +import com.oath.micro.server.servers.model.AllData; +import com.oath.micro.server.servers.model.FilterData; +import com.oath.micro.server.servers.model.ServerData; +import com.oath.micro.server.servers.model.ServletData; + +@AllArgsConstructor +public class TomcatApplicationFactory implements ServerApplicationFactory { + + + + + public ServerApplication createApp(final Module module, final ApplicationContext rootContext) { + ModuleDataExtractor extractor = new ModuleDataExtractor(module); + PersistentList resources = extractor.getRestResources(rootContext); + + Environment environment = rootContext.getBean(Environment.class); + + environment.assureModule(module); + String fullRestResource = "/" + module.getContext() + "/*"; + + ServerData serverData = new ServerData(environment.getModuleBean(module).getPort(), + resources, + rootContext, fullRestResource, module); + List filterDataList = extractor.createFilteredDataList(serverData); + List servletDataList = extractor.createServletDataList(serverData); + + TomcatApplication app = new TomcatApplication( + new AllData(serverData, + filterDataList, + servletDataList, + module.getListeners(serverData), + module.getRequestListeners(serverData))); + return app; + } +} diff --git a/micro-tomcat/src/main/java/com/oath/micro/server/servers/tomcat/TomcatListener.java b/micro-tomcat/src/main/java/com/oath/micro/server/servers/tomcat/TomcatListener.java new file mode 100644 index 000000000..0c3d27050 --- /dev/null +++ b/micro-tomcat/src/main/java/com/oath/micro/server/servers/tomcat/TomcatListener.java @@ -0,0 +1,57 @@ +package com.oath.micro.server.servers.tomcat; + +import java.util.Set; + +import javax.servlet.ServletContainerInitializer; +import javax.servlet.ServletContext; +import javax.servlet.ServletContextListener; +import javax.servlet.ServletException; +import javax.servlet.ServletRequestListener; + + +import com.oath.cyclops.types.persistent.PersistentList; +import lombok.AllArgsConstructor; + +import com.oath.micro.server.servers.FilterConfigurer; +import com.oath.micro.server.servers.JaxRsServletConfigurer; +import com.oath.micro.server.servers.ServerThreadLocalVariables; +import com.oath.micro.server.servers.ServletConfigurer; +import com.oath.micro.server.servers.ServletContextListenerConfigurer; +import com.oath.micro.server.servers.model.FilterData; +import com.oath.micro.server.servers.model.ServerData; +import com.oath.micro.server.servers.model.ServletData; +@AllArgsConstructor +public class TomcatListener implements ServletContainerInitializer { + + + private final JaxRsServletConfigurer jaxRsConfigurer; + private final ServerData serverData; + + private final PersistentList filterData; + private final PersistentList servletData; + private final PersistentList servletContextListenerData; + private final PersistentList servletRequestListenerData; + + + @Override + public void onStartup(Set> classes, ServletContext webappContext) + throws ServletException { + try { + ServerThreadLocalVariables.getContext().set(serverData.getModule().getContext()); + + jaxRsConfigurer.addServlet(this.serverData,webappContext); + + new ServletConfigurer(serverData, servletData).addServlets(webappContext); + + new FilterConfigurer(serverData, this.filterData).addFilters(webappContext); + new ServletContextListenerConfigurer(serverData, servletContextListenerData, servletRequestListenerData).addListeners(webappContext); + + } + catch (Exception ex) { + + } + } + + + +} \ No newline at end of file diff --git a/micro-tomcat/src/main/java/com/oath/micro/server/servers/tomcat/plugin/TomcatPlugin.java b/micro-tomcat/src/main/java/com/oath/micro/server/servers/tomcat/plugin/TomcatPlugin.java new file mode 100644 index 000000000..48dba1da0 --- /dev/null +++ b/micro-tomcat/src/main/java/com/oath/micro/server/servers/tomcat/plugin/TomcatPlugin.java @@ -0,0 +1,18 @@ +package com.oath.micro.server.servers.tomcat.plugin; + +import java.util.Optional; + +import com.oath.micro.server.Plugin; +import com.oath.micro.server.servers.ServerApplicationFactory; +import com.oath.micro.server.servers.tomcat.TomcatApplicationFactory; + + +public class TomcatPlugin implements Plugin{ + + @Override + public Optional serverApplicationFactory(){ + return Optional.of(new TomcatApplicationFactory()); + } + + +} diff --git a/micro-tomcat/src/main/resources/META-INF/services/com.aol.micro.server.Plugin b/micro-tomcat/src/main/resources/META-INF/services/com.aol.micro.server.Plugin deleted file mode 100644 index 397770690..000000000 --- a/micro-tomcat/src/main/resources/META-INF/services/com.aol.micro.server.Plugin +++ /dev/null @@ -1 +0,0 @@ -com.aol.micro.server.servers.tomcat.plugin.TomcatPlugin \ No newline at end of file diff --git a/micro-tomcat/src/main/resources/META-INF/services/com.oath.micro.server.Plugin b/micro-tomcat/src/main/resources/META-INF/services/com.oath.micro.server.Plugin new file mode 100644 index 000000000..b608d6d79 --- /dev/null +++ b/micro-tomcat/src/main/resources/META-INF/services/com.oath.micro.server.Plugin @@ -0,0 +1 @@ +com.oath.micro.server.servers.tomcat.plugin.TomcatPlugin \ No newline at end of file diff --git a/micro-tomcat/src/test/java/app/access/log/micro/server/servers/AccessLogConfigTest.java b/micro-tomcat/src/test/java/app/access/log/micro/server/servers/AccessLogConfigTest.java index 3c97147d2..57d456fac 100644 --- a/micro-tomcat/src/test/java/app/access/log/micro/server/servers/AccessLogConfigTest.java +++ b/micro-tomcat/src/test/java/app/access/log/micro/server/servers/AccessLogConfigTest.java @@ -11,8 +11,8 @@ import org.junit.Before; import org.junit.Test; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; @Microserver(properties={"access.log.output", "${user.home}"}) public class AccessLogConfigTest { diff --git a/micro-tomcat/src/test/java/app/async/com/aol/micro/server/AsyncAppRunner.java b/micro-tomcat/src/test/java/app/async/com/aol/micro/server/AsyncAppRunner.java deleted file mode 100644 index a5b427b75..000000000 --- a/micro-tomcat/src/test/java/app/async/com/aol/micro/server/AsyncAppRunner.java +++ /dev/null @@ -1,58 +0,0 @@ -package app.async.com.aol.micro.server; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.io.IOException; -import java.util.Properties; -import java.util.concurrent.ExecutionException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.spring.properties.PropertyFileConfig; -import com.aol.micro.server.testing.RestAgent; - -@Microserver -public class AsyncAppRunner { - - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer() throws InterruptedException{ - - server = new MicroserverApp( ()-> "async-app"); - Thread.sleep(1000); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - Thread.sleep(2000); - - assertThat(rest.get("http://localhost:8080/async-app/async/expensive"),is(";test!;test!;test!")); - - } - - @Test - public void loadProperties() throws IOException{ - - Properties props = new PropertyFileConfig(true).propertyFactory() ; - assertThat(props.getProperty("test"),is("hello world")); - } - - - -} \ No newline at end of file diff --git a/micro-tomcat/src/test/java/app/async/com/aol/micro/server/AsyncResource.java b/micro-tomcat/src/test/java/app/async/com/aol/micro/server/AsyncResource.java deleted file mode 100644 index 34f8f0079..000000000 --- a/micro-tomcat/src/test/java/app/async/com/aol/micro/server/AsyncResource.java +++ /dev/null @@ -1,57 +0,0 @@ -package app.async.com.aol.micro.server; - -import java.util.Arrays; -import java.util.List; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.container.AsyncResponse; -import javax.ws.rs.container.Suspended; - -import cyclops.async.SimpleReact; -import cyclops.reactive.FutureStream; -import cyclops.reactive.ReactiveSeq; -import org.springframework.stereotype.Component; - - -import com.aol.micro.server.auto.discovery.RestResource; -import com.aol.micro.server.testing.RestAgent; - -@Path("/async") -@Component -public class AsyncResource implements RestResource{ - - private final SimpleReact simpleReact =new SimpleReact(); - private final List urls = Arrays.asList("http://localhost:8080/async-app/async/ping2", - "http://localhost:8080/async-app/async/ping", - "http://localhost:8080/async-app/async/ping", - "http://localhost:8080/async-app/async/ping"); - - private final RestAgent client = new RestAgent(); - - @GET - @Path("/expensive") - @Produces("text/plain") - public void expensive(@Suspended AsyncResponse asyncResponse){ - - FutureStream.builder().fromIterable(urls) - .then(it->client.get(it)) - .onFail(it -> "") - .peek(it -> - System.out.println(it)) - .convertToSimpleReact() - .allOf(data -> { - System.out.println(data); - return asyncResponse.resume(ReactiveSeq.fromIterable(data).join(";")); }); - } - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "test!"; - } - - -} diff --git a/micro-tomcat/src/test/java/app/async/com/aol/micro/server/Simple.java b/micro-tomcat/src/test/java/app/async/com/aol/micro/server/Simple.java deleted file mode 100644 index edefa80ef..000000000 --- a/micro-tomcat/src/test/java/app/async/com/aol/micro/server/Simple.java +++ /dev/null @@ -1,16 +0,0 @@ -package app.async.com.aol.micro.server; - -import java.io.IOException; -import java.util.Properties; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Config; -import com.aol.micro.server.spring.properties.PropertyFileConfig; - -public class Simple { - - public static void main(String[] args) throws IOException{ - - new MicroserverApp(()->"test-app").run(); - } -} diff --git a/micro-tomcat/src/test/java/app/async/com/aol/micro/server/SimpleApp.java b/micro-tomcat/src/test/java/app/async/com/aol/micro/server/SimpleApp.java deleted file mode 100644 index 919b7c6b0..000000000 --- a/micro-tomcat/src/test/java/app/async/com/aol/micro/server/SimpleApp.java +++ /dev/null @@ -1,24 +0,0 @@ -package app.async.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.Rest; - - - -@Rest -@Path("/test") -public class SimpleApp { - - public static void main(String[] args){ - new MicroserverApp(()->"test-app").run(); - } - @GET - public String myEndPoint(){ - return "hello world!"; - } - - -} diff --git a/micro-tomcat/src/test/java/app/async/com/oath/micro/server/AsyncAppRunner.java b/micro-tomcat/src/test/java/app/async/com/oath/micro/server/AsyncAppRunner.java new file mode 100644 index 000000000..79933ea7a --- /dev/null +++ b/micro-tomcat/src/test/java/app/async/com/oath/micro/server/AsyncAppRunner.java @@ -0,0 +1,58 @@ +package app.async.com.oath.micro.server; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.io.IOException; +import java.util.Properties; +import java.util.concurrent.ExecutionException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.spring.properties.PropertyFileConfig; +import com.oath.micro.server.testing.RestAgent; + +@Microserver +public class AsyncAppRunner { + + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer() throws InterruptedException{ + + server = new MicroserverApp( ()-> "async-app"); + Thread.sleep(1000); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + Thread.sleep(2000); + + assertThat(rest.get("http://localhost:8080/async-app/async/expensive"),is(";test!;test!;test!")); + + } + + @Test + public void loadProperties() throws IOException{ + + Properties props = new PropertyFileConfig(true).propertyFactory() ; + assertThat(props.getProperty("test"),is("hello world")); + } + + + +} \ No newline at end of file diff --git a/micro-tomcat/src/test/java/app/async/com/oath/micro/server/AsyncResource.java b/micro-tomcat/src/test/java/app/async/com/oath/micro/server/AsyncResource.java new file mode 100644 index 000000000..3d230ee9b --- /dev/null +++ b/micro-tomcat/src/test/java/app/async/com/oath/micro/server/AsyncResource.java @@ -0,0 +1,57 @@ +package app.async.com.oath.micro.server; + +import java.util.Arrays; +import java.util.List; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.container.AsyncResponse; +import javax.ws.rs.container.Suspended; + +import cyclops.async.SimpleReact; +import cyclops.reactive.FutureStream; +import cyclops.reactive.ReactiveSeq; +import org.springframework.stereotype.Component; + + +import com.oath.micro.server.auto.discovery.RestResource; +import com.oath.micro.server.testing.RestAgent; + +@Path("/async") +@Component +public class AsyncResource implements RestResource{ + + private final SimpleReact simpleReact =new SimpleReact(); + private final List urls = Arrays.asList("http://localhost:8080/async-app/async/ping2", + "http://localhost:8080/async-app/async/ping", + "http://localhost:8080/async-app/async/ping", + "http://localhost:8080/async-app/async/ping"); + + private final RestAgent client = new RestAgent(); + + @GET + @Path("/expensive") + @Produces("text/plain") + public void expensive(@Suspended AsyncResponse asyncResponse){ + + FutureStream.builder().fromIterable(urls) + .then(it->client.get(it)) + .onFail(it -> "") + .peek(it -> + System.out.println(it)) + .convertToSimpleReact() + .allOf(data -> { + System.out.println(data); + return asyncResponse.resume(ReactiveSeq.fromIterable(data).join(";")); }); + } + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "test!"; + } + + +} diff --git a/micro-tomcat/src/test/java/app/async/com/oath/micro/server/Simple.java b/micro-tomcat/src/test/java/app/async/com/oath/micro/server/Simple.java new file mode 100644 index 000000000..3eb3e7504 --- /dev/null +++ b/micro-tomcat/src/test/java/app/async/com/oath/micro/server/Simple.java @@ -0,0 +1,13 @@ +package app.async.com.oath.micro.server; + +import java.io.IOException; + +import com.oath.micro.server.MicroserverApp; + +public class Simple { + + public static void main(String[] args) throws IOException{ + + new MicroserverApp(()->"test-app").run(); + } +} diff --git a/micro-tomcat/src/test/java/app/async/com/oath/micro/server/SimpleApp.java b/micro-tomcat/src/test/java/app/async/com/oath/micro/server/SimpleApp.java new file mode 100644 index 000000000..916d0330e --- /dev/null +++ b/micro-tomcat/src/test/java/app/async/com/oath/micro/server/SimpleApp.java @@ -0,0 +1,24 @@ +package app.async.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.auto.discovery.Rest; + + + +@Rest +@Path("/test") +public class SimpleApp { + + public static void main(String[] args){ + new MicroserverApp(()->"test-app").run(); + } + @GET + public String myEndPoint(){ + return "hello world!"; + } + + +} diff --git a/micro-tomcat/src/test/java/app/custom/binder/test/SimpleApp.java b/micro-tomcat/src/test/java/app/custom/binder/test/SimpleApp.java index 35fda203b..2906df5fd 100644 --- a/micro-tomcat/src/test/java/app/custom/binder/test/SimpleApp.java +++ b/micro-tomcat/src/test/java/app/custom/binder/test/SimpleApp.java @@ -7,9 +7,9 @@ import org.glassfish.jersey.server.ResourceConfig; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.module.ConfigurableModule; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.auto.discovery.Rest; +import com.oath.micro.server.module.ConfigurableModule; diff --git a/micro-tomcat/src/test/java/app/embedded/com/aol/micro/server/AltAppResource.java b/micro-tomcat/src/test/java/app/embedded/com/aol/micro/server/AltAppResource.java deleted file mode 100644 index d4b8eff5c..000000000 --- a/micro-tomcat/src/test/java/app/embedded/com/aol/micro/server/AltAppResource.java +++ /dev/null @@ -1,23 +0,0 @@ -package app.embedded.com.aol.micro.server; - -import java.util.ArrayList; -import java.util.List; - -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.stereotype.Component; - -@Component -@Path("/alt-status") -public class AltAppResource implements AltAppRestResource { - - @POST - @Produces("application/json") - @Path("/ping") - public List ping(ImmutableEntity entity) { - return entity.getList(); - } - -} diff --git a/micro-tomcat/src/test/java/app/embedded/com/aol/micro/server/AltAppRestResource.java b/micro-tomcat/src/test/java/app/embedded/com/aol/micro/server/AltAppRestResource.java deleted file mode 100644 index 8cb2643e3..000000000 --- a/micro-tomcat/src/test/java/app/embedded/com/aol/micro/server/AltAppRestResource.java +++ /dev/null @@ -1,7 +0,0 @@ -package app.embedded.com.aol.micro.server; - -import com.aol.micro.server.auto.discovery.RestResource; - -public interface AltAppRestResource extends RestResource { - -} diff --git a/micro-tomcat/src/test/java/app/embedded/com/aol/micro/server/EmbeddedAppLocalMain.java b/micro-tomcat/src/test/java/app/embedded/com/aol/micro/server/EmbeddedAppLocalMain.java deleted file mode 100644 index bc73c2862..000000000 --- a/micro-tomcat/src/test/java/app/embedded/com/aol/micro/server/EmbeddedAppLocalMain.java +++ /dev/null @@ -1,24 +0,0 @@ -package app.embedded.com.aol.micro.server; - -import java.util.Arrays; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.module.EmbeddedModule; - -@Microserver(basePackages = { "app.embedded.com.aol.micro.server" }) -public class EmbeddedAppLocalMain { - - - public static void main(String[] args) throws InterruptedException { - - new MicroserverApp( - EmbeddedModule.tagInterfaceModule(Arrays.asList(TestAppRestResource.class),"test-app"), - EmbeddedModule.tagInterfaceModule(Arrays.asList(AltAppRestResource.class),"alternative-app")).start(); - - - - } - - -} diff --git a/micro-tomcat/src/test/java/app/embedded/com/aol/micro/server/EmbeddedAppTest.java b/micro-tomcat/src/test/java/app/embedded/com/aol/micro/server/EmbeddedAppTest.java deleted file mode 100644 index 12c1148d1..000000000 --- a/micro-tomcat/src/test/java/app/embedded/com/aol/micro/server/EmbeddedAppTest.java +++ /dev/null @@ -1,103 +0,0 @@ -package app.embedded.com.aol.micro.server; - -import static org.hamcrest.Matchers.hasItem; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; - -import javax.ws.rs.NotFoundException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.springframework.util.concurrent.ListenableFuture; -import org.springframework.util.concurrent.ListenableFutureCallback; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.module.EmbeddedModule; -import com.aol.micro.server.testing.RestAgent; -@Ignore //micro-monolith doesn't work with Tomcat at the moment, because tomcat MBean registrations clash -public class EmbeddedAppTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - - @Before - public void startServer(){ - server = new MicroserverApp(EmbeddedAppLocalMain.class, - EmbeddedModule.tagInterfaceModule(Arrays.asList(TestAppRestResource.class),"test-app"), - EmbeddedModule.tagInterfaceModule(Arrays.asList(AltAppRestResource.class),"alternative-app")); - server.start(); - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void confirmExpectedUrlsPresentTest() throws InterruptedException, ExecutionException{ - - assertThat(rest.get("http://localhost:8080/test-app/test-status/ping"),is("test!")); - - - assertThat((List)rest.post("http://localhost:8081/alternative-app/alt-status/ping",new ImmutableEntity("value",Arrays.asList("hello","world")),List.class), - hasItem("hello")); - - } - - - @Test - public void nonBlockingRestClientTest(){ - assertThat(rest.get("http://localhost:8080/test-app/test-status/rest-calls"),is("-*test!-*test!")); - } - - CompletableFuture toCompletableFuture( - final ListenableFuture listenableFuture - ) { - //create an instance of CompletableFuture - CompletableFuture completable = new CompletableFuture() { - @Override - public boolean cancel(boolean mayInterruptIfRunning) { - // propagate cancel to the listenable future - boolean result = listenableFuture.cancel(mayInterruptIfRunning); - super.cancel(mayInterruptIfRunning); - return result; - } - }; - - // add callback - listenableFuture.addCallback(new ListenableFutureCallback() { - @Override - public void onSuccess(T result) { - completable.complete(result); - } - - @Override - public void onFailure(Throwable t) { - completable.completeExceptionally(t); - } - }); - return completable; - } - - @Test(expected=NotFoundException.class) - public void confirmAltAppCantUseTestAppResources(){ - - assertThat(rest.get("http://localhost:8080/alternative-app/test-status/ping"),is("test!")); - - } - @Test(expected=NotFoundException.class) - public void confirmTestAppCantUseAltAppResources(){ - - assertThat((List)rest.post("http://localhost:8081/test-app/alt-status/ping",new ImmutableEntity("value",Arrays.asList("hello","world")),List.class), - hasItem("hello")); - - } -} diff --git a/micro-tomcat/src/test/java/app/embedded/com/aol/micro/server/ImmutableEntity.java b/micro-tomcat/src/test/java/app/embedded/com/aol/micro/server/ImmutableEntity.java deleted file mode 100644 index cd593f123..000000000 --- a/micro-tomcat/src/test/java/app/embedded/com/aol/micro/server/ImmutableEntity.java +++ /dev/null @@ -1,29 +0,0 @@ -package app.embedded.com.aol.micro.server; - -import java.util.List; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Builder; - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "") -@XmlRootElement(name = "immutable") -@Getter -@AllArgsConstructor -@Builder -public class ImmutableEntity { - - private final String value; - private final List list; - - public ImmutableEntity() { - this(null,null); - } - -} diff --git a/micro-tomcat/src/test/java/app/embedded/com/aol/micro/server/TestAppResource.java b/micro-tomcat/src/test/java/app/embedded/com/aol/micro/server/TestAppResource.java deleted file mode 100644 index 24c0ebe27..000000000 --- a/micro-tomcat/src/test/java/app/embedded/com/aol/micro/server/TestAppResource.java +++ /dev/null @@ -1,49 +0,0 @@ -package app.embedded.com.aol.micro.server; - -import java.util.Arrays; -import java.util.List; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import cyclops.async.SimpleReact; -import cyclops.reactive.FutureStream; -import org.springframework.stereotype.Component; - - -import com.aol.micro.server.testing.RestAgent; -@Component -@Path("/test-status") -public class TestAppResource implements TestAppRestResource { - - private final SimpleReact simpleReact = new SimpleReact(); - private final RestAgent template = new RestAgent(); - private final List urls = Arrays.asList("http://localhost:8081/alternative-app/alt-status/ping", - "http://localhost:8080/test-app/test-status/ping", - "http://localhost:8082/simple-app/status/ping", - "http://localhost:8080/test-app/test-status/ping"); - - - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "test!"; - } - - @GET - @Produces("text/plain") - @Path("/rest-calls") - public String restCallResult(){ - - return FutureStream.builder().fromIterable(urls) - .map(it ->template.get(it)) - .then(it -> "*"+it) - .peek(loadedAndModified -> System.out.println(loadedAndModified)) - .block().stream().reduce("", (acc,next) -> acc+"-"+next); - - } - -} diff --git a/micro-tomcat/src/test/java/app/embedded/com/aol/micro/server/TestAppRestResource.java b/micro-tomcat/src/test/java/app/embedded/com/aol/micro/server/TestAppRestResource.java deleted file mode 100644 index 3133fd8cc..000000000 --- a/micro-tomcat/src/test/java/app/embedded/com/aol/micro/server/TestAppRestResource.java +++ /dev/null @@ -1,7 +0,0 @@ -package app.embedded.com.aol.micro.server; - -import com.aol.micro.server.auto.discovery.RestResource; - -public interface TestAppRestResource extends RestResource { - -} diff --git a/micro-tomcat/src/test/java/app/embedded/com/oath/micro/server/AltAppResource.java b/micro-tomcat/src/test/java/app/embedded/com/oath/micro/server/AltAppResource.java new file mode 100644 index 000000000..1835ababe --- /dev/null +++ b/micro-tomcat/src/test/java/app/embedded/com/oath/micro/server/AltAppResource.java @@ -0,0 +1,22 @@ +package app.embedded.com.oath.micro.server; + +import java.util.List; + +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.stereotype.Component; + +@Component +@Path("/alt-status") +public class AltAppResource implements AltAppRestResource { + + @POST + @Produces("application/json") + @Path("/ping") + public List ping(ImmutableEntity entity) { + return entity.getList(); + } + +} diff --git a/micro-tomcat/src/test/java/app/embedded/com/oath/micro/server/AltAppRestResource.java b/micro-tomcat/src/test/java/app/embedded/com/oath/micro/server/AltAppRestResource.java new file mode 100644 index 000000000..7045a4f35 --- /dev/null +++ b/micro-tomcat/src/test/java/app/embedded/com/oath/micro/server/AltAppRestResource.java @@ -0,0 +1,7 @@ +package app.embedded.com.oath.micro.server; + +import com.oath.micro.server.auto.discovery.RestResource; + +public interface AltAppRestResource extends RestResource { + +} diff --git a/micro-tomcat/src/test/java/app/embedded/com/oath/micro/server/EmbeddedAppLocalMain.java b/micro-tomcat/src/test/java/app/embedded/com/oath/micro/server/EmbeddedAppLocalMain.java new file mode 100644 index 000000000..dbb290069 --- /dev/null +++ b/micro-tomcat/src/test/java/app/embedded/com/oath/micro/server/EmbeddedAppLocalMain.java @@ -0,0 +1,24 @@ +package app.embedded.com.oath.micro.server; + +import java.util.Arrays; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.module.EmbeddedModule; + +@Microserver(basePackages = { "app.embedded.com.oath.micro.server" }) +public class EmbeddedAppLocalMain { + + + public static void main(String[] args) throws InterruptedException { + + new MicroserverApp( + EmbeddedModule.tagInterfaceModule(Arrays.asList(TestAppRestResource.class),"test-app"), + EmbeddedModule.tagInterfaceModule(Arrays.asList(AltAppRestResource.class),"alternative-app")).start(); + + + + } + + +} diff --git a/micro-tomcat/src/test/java/app/embedded/com/oath/micro/server/EmbeddedAppTest.java b/micro-tomcat/src/test/java/app/embedded/com/oath/micro/server/EmbeddedAppTest.java new file mode 100644 index 000000000..eb0daed57 --- /dev/null +++ b/micro-tomcat/src/test/java/app/embedded/com/oath/micro/server/EmbeddedAppTest.java @@ -0,0 +1,103 @@ +package app.embedded.com.oath.micro.server; + +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; + +import javax.ws.rs.NotFoundException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.springframework.util.concurrent.ListenableFuture; +import org.springframework.util.concurrent.ListenableFutureCallback; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.module.EmbeddedModule; +import com.oath.micro.server.testing.RestAgent; +@Ignore //micro-monolith doesn't work with Tomcat at the moment, because tomcat MBean registrations clash +public class EmbeddedAppTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + + @Before + public void startServer(){ + server = new MicroserverApp(EmbeddedAppLocalMain.class, + EmbeddedModule.tagInterfaceModule(Arrays.asList(TestAppRestResource.class),"test-app"), + EmbeddedModule.tagInterfaceModule(Arrays.asList(AltAppRestResource.class),"alternative-app")); + server.start(); + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void confirmExpectedUrlsPresentTest() throws InterruptedException, ExecutionException{ + + assertThat(rest.get("http://localhost:8080/test-app/test-status/ping"),is("test!")); + + + assertThat((List)rest.post("http://localhost:8081/alternative-app/alt-status/ping",new ImmutableEntity("value",Arrays.asList("hello","world")),List.class), + hasItem("hello")); + + } + + + @Test + public void nonBlockingRestClientTest(){ + assertThat(rest.get("http://localhost:8080/test-app/test-status/rest-calls"),is("-*test!-*test!")); + } + + CompletableFuture toCompletableFuture( + final ListenableFuture listenableFuture + ) { + //create an instance of CompletableFuture + CompletableFuture completable = new CompletableFuture() { + @Override + public boolean cancel(boolean mayInterruptIfRunning) { + // propagate cancel to the listenable future + boolean result = listenableFuture.cancel(mayInterruptIfRunning); + super.cancel(mayInterruptIfRunning); + return result; + } + }; + + // add callback + listenableFuture.addCallback(new ListenableFutureCallback() { + @Override + public void onSuccess(T result) { + completable.complete(result); + } + + @Override + public void onFailure(Throwable t) { + completable.completeExceptionally(t); + } + }); + return completable; + } + + @Test(expected=NotFoundException.class) + public void confirmAltAppCantUseTestAppResources(){ + + assertThat(rest.get("http://localhost:8080/alternative-app/test-status/ping"),is("test!")); + + } + @Test(expected=NotFoundException.class) + public void confirmTestAppCantUseAltAppResources(){ + + assertThat((List)rest.post("http://localhost:8081/test-app/alt-status/ping",new ImmutableEntity("value",Arrays.asList("hello","world")),List.class), + hasItem("hello")); + + } +} diff --git a/micro-tomcat/src/test/java/app/embedded/com/oath/micro/server/ImmutableEntity.java b/micro-tomcat/src/test/java/app/embedded/com/oath/micro/server/ImmutableEntity.java new file mode 100644 index 000000000..337b63b89 --- /dev/null +++ b/micro-tomcat/src/test/java/app/embedded/com/oath/micro/server/ImmutableEntity.java @@ -0,0 +1,29 @@ +package app.embedded.com.oath.micro.server; + +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Builder; + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "") +@XmlRootElement(name = "immutable") +@Getter +@AllArgsConstructor +@Builder +public class ImmutableEntity { + + private final String value; + private final List list; + + public ImmutableEntity() { + this(null,null); + } + +} diff --git a/micro-tomcat/src/test/java/app/embedded/com/oath/micro/server/TestAppResource.java b/micro-tomcat/src/test/java/app/embedded/com/oath/micro/server/TestAppResource.java new file mode 100644 index 000000000..ebf830d95 --- /dev/null +++ b/micro-tomcat/src/test/java/app/embedded/com/oath/micro/server/TestAppResource.java @@ -0,0 +1,49 @@ +package app.embedded.com.oath.micro.server; + +import java.util.Arrays; +import java.util.List; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import cyclops.async.SimpleReact; +import cyclops.reactive.FutureStream; +import org.springframework.stereotype.Component; + + +import com.oath.micro.server.testing.RestAgent; +@Component +@Path("/test-status") +public class TestAppResource implements TestAppRestResource { + + private final SimpleReact simpleReact = new SimpleReact(); + private final RestAgent template = new RestAgent(); + private final List urls = Arrays.asList("http://localhost:8081/alternative-app/alt-status/ping", + "http://localhost:8080/test-app/test-status/ping", + "http://localhost:8082/simple-app/status/ping", + "http://localhost:8080/test-app/test-status/ping"); + + + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "test!"; + } + + @GET + @Produces("text/plain") + @Path("/rest-calls") + public String restCallResult(){ + + return FutureStream.builder().fromIterable(urls) + .map(it ->template.get(it)) + .then(it -> "*"+it) + .peek(loadedAndModified -> System.out.println(loadedAndModified)) + .block().stream().reduce("", (acc,next) -> acc+"-"+next); + + } + +} diff --git a/micro-tomcat/src/test/java/app/embedded/com/oath/micro/server/TestAppRestResource.java b/micro-tomcat/src/test/java/app/embedded/com/oath/micro/server/TestAppRestResource.java new file mode 100644 index 000000000..7d4df5753 --- /dev/null +++ b/micro-tomcat/src/test/java/app/embedded/com/oath/micro/server/TestAppRestResource.java @@ -0,0 +1,7 @@ +package app.embedded.com.oath.micro.server; + +import com.oath.micro.server.auto.discovery.RestResource; + +public interface TestAppRestResource extends RestResource { + +} diff --git a/micro-tomcat/src/test/java/app/filter/com/aol/micro/server/AutodiscoveredFilter.java b/micro-tomcat/src/test/java/app/filter/com/aol/micro/server/AutodiscoveredFilter.java deleted file mode 100644 index 52a8959db..000000000 --- a/micro-tomcat/src/test/java/app/filter/com/aol/micro/server/AutodiscoveredFilter.java +++ /dev/null @@ -1,70 +0,0 @@ -package app.filter.com.aol.micro.server; - -import java.io.IOException; - -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; - -import cyclops.control.Either; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - - -import com.aol.micro.server.auto.discovery.AutoFilterConfiguration; - -import lombok.Getter; -import lombok.Setter; - -@Component -public class AutodiscoveredFilter implements AutoFilterConfiguration { - - @Autowired - Bean bean; - @Getter - @Setter - private static volatile int called= 0; - - @Getter - private static boolean beanSet = false; - - @Override - public String[] getMapping() { - return new String[] { "/*" }; - } - public Either,Filter> getFilter(){ - - return Either.left(org.springframework.web.filter.DelegatingFilterProxy.class); - - } - public String getName(){ - return "autodiscoveredFilter"; - } - - @Override - public void init(FilterConfig filterConfig) throws ServletException { - - } - - @Override - public void doFilter(ServletRequest request, ServletResponse response, - FilterChain chain) throws IOException, ServletException { - - called++; - if(bean!=null) - beanSet =true; - chain.doFilter(request, response); - } - - @Override - public void destroy() { - - - } - - - -} \ No newline at end of file diff --git a/micro-tomcat/src/test/java/app/filter/com/aol/micro/server/Bean.java b/micro-tomcat/src/test/java/app/filter/com/aol/micro/server/Bean.java deleted file mode 100644 index f95b44b05..000000000 --- a/micro-tomcat/src/test/java/app/filter/com/aol/micro/server/Bean.java +++ /dev/null @@ -1,8 +0,0 @@ -package app.filter.com.aol.micro.server; - -import org.springframework.stereotype.Component; - -@Component -public class Bean { - -} diff --git a/micro-tomcat/src/test/java/app/filter/com/aol/micro/server/ConfiguredFilter.java b/micro-tomcat/src/test/java/app/filter/com/aol/micro/server/ConfiguredFilter.java deleted file mode 100644 index e00bc941b..000000000 --- a/micro-tomcat/src/test/java/app/filter/com/aol/micro/server/ConfiguredFilter.java +++ /dev/null @@ -1,38 +0,0 @@ -package app.filter.com.aol.micro.server; - -import java.io.IOException; - -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; - -import lombok.Getter; - -public class ConfiguredFilter implements Filter { - - @Getter - private static volatile int called= 0; - @Override - public void init(FilterConfig filterConfig) throws ServletException { - // TODO Auto-generated method stub - - } - - @Override - public void doFilter(ServletRequest request, ServletResponse response, - FilterChain chain) throws IOException, ServletException { - called++; - chain.doFilter(request, response); - - } - - @Override - public void destroy() { - // TODO Auto-generated method stub - - } - -} diff --git a/micro-tomcat/src/test/java/app/filter/com/aol/micro/server/FilterAppLocalMain.java b/micro-tomcat/src/test/java/app/filter/com/aol/micro/server/FilterAppLocalMain.java deleted file mode 100644 index 25dc01cc3..000000000 --- a/micro-tomcat/src/test/java/app/filter/com/aol/micro/server/FilterAppLocalMain.java +++ /dev/null @@ -1,22 +0,0 @@ -package app.filter.com.aol.micro.server; - -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; - -import app.servlet.com.aol.micro.server.AppRunnerLocalMain; - -import com.aol.micro.server.MicroserverApp; -@Configuration -@ComponentScan(basePackages = { "app.filter.com.aol.micro.server" }) -public class FilterAppLocalMain { - - - - - public static void main(String[] args) throws InterruptedException { - - new MicroserverApp( FilterAppLocalMain.class, () -> "filter-app") - .run(); - } - - } \ No newline at end of file diff --git a/micro-tomcat/src/test/java/app/filter/com/aol/micro/server/FilterRunnerTest.java b/micro-tomcat/src/test/java/app/filter/com/aol/micro/server/FilterRunnerTest.java deleted file mode 100644 index 9b16a9a24..000000000 --- a/micro-tomcat/src/test/java/app/filter/com/aol/micro/server/FilterRunnerTest.java +++ /dev/null @@ -1,65 +0,0 @@ -package app.filter.com.aol.micro.server; - - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.Arrays; -import java.util.Map; -import java.util.concurrent.ExecutionException; - -import javax.servlet.Filter; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.testing.RestAgent; -import com.aol.micro.server.utility.HashMapBuilder; - - - -public class FilterRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer() throws InterruptedException{ - Thread.sleep(500); - Map filters = HashMapBuilder.map("/filter-app/status/ping2",new ConfiguredFilter()).build(); - server = new MicroserverApp(ConfigurableModule.builder() - .context("filter-app") - .filters(filters ) - .requestListeners(Arrays.asList(new org.springframework.web.context.request.RequestContextListener())).build()); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void testAutoDiscoveredFilter() throws InterruptedException, ExecutionException{ - AutodiscoveredFilter.setCalled(0); - - assertThat(rest.get("http://localhost:8080/filter-app/status/ping"),is("ok")); - assertThat(AutodiscoveredFilter.getCalled(),is(1)); - assertThat(AutodiscoveredFilter.isBeanSet(),is(true)); - } - @Test - public void testConfiguredFilter() throws InterruptedException, ExecutionException{ - - assertThat(ConfiguredFilter.getCalled(),is(0)); - assertThat(rest.get("http://localhost:8080/filter-app/status/ping2"),is("ok")); - assertThat(ConfiguredFilter.getCalled(),is(1)); - } - - - - -} diff --git a/micro-tomcat/src/test/java/app/filter/com/aol/micro/server/FilterStatusResource.java b/micro-tomcat/src/test/java/app/filter/com/aol/micro/server/FilterStatusResource.java deleted file mode 100644 index 2d046711b..000000000 --- a/micro-tomcat/src/test/java/app/filter/com/aol/micro/server/FilterStatusResource.java +++ /dev/null @@ -1,37 +0,0 @@ -package app.filter.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.config.ConfigurableBeanFactory; -import org.springframework.context.annotation.Scope; -import org.springframework.stereotype.Component; -import org.springframework.web.context.WebApplicationContext; - -import com.aol.micro.server.auto.discovery.RestResource; - -@Component -@Scope(value=ConfigurableBeanFactory.SCOPE_PROTOTYPE) -@Path("/status") -public class FilterStatusResource implements RestResource { - - @Autowired - private RequestScopeUserInfo info; - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - info.print(); - return "ok"; - } - @GET - @Produces("text/plain") - @Path("/ping2") - public String ping2() { - return "ok"; - } - -} \ No newline at end of file diff --git a/micro-tomcat/src/test/java/app/filter/com/aol/micro/server/RequestScopeUserInfo.java b/micro-tomcat/src/test/java/app/filter/com/aol/micro/server/RequestScopeUserInfo.java deleted file mode 100644 index c41605c39..000000000 --- a/micro-tomcat/src/test/java/app/filter/com/aol/micro/server/RequestScopeUserInfo.java +++ /dev/null @@ -1,20 +0,0 @@ -package app.filter.com.aol.micro.server; - -import javax.servlet.http.HttpServletRequest; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Scope; -import org.springframework.context.annotation.ScopedProxyMode; -import org.springframework.stereotype.Component; -import org.springframework.web.context.WebApplicationContext; - -@Component -@Scope(value=WebApplicationContext.SCOPE_REQUEST,proxyMode=ScopedProxyMode.TARGET_CLASS) -public class RequestScopeUserInfo { - @Autowired - private HttpServletRequest request; - - public void print(){ - System.out.println(request.getAttribute("oc.info")); - } -} diff --git a/micro-tomcat/src/test/java/app/filter/com/oath/micro/server/AutodiscoveredFilter.java b/micro-tomcat/src/test/java/app/filter/com/oath/micro/server/AutodiscoveredFilter.java new file mode 100644 index 000000000..1f6dfc284 --- /dev/null +++ b/micro-tomcat/src/test/java/app/filter/com/oath/micro/server/AutodiscoveredFilter.java @@ -0,0 +1,70 @@ +package app.filter.com.oath.micro.server; + +import java.io.IOException; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; + +import cyclops.control.Either; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + + +import com.oath.micro.server.auto.discovery.AutoFilterConfiguration; + +import lombok.Getter; +import lombok.Setter; + +@Component +public class AutodiscoveredFilter implements AutoFilterConfiguration { + + @Autowired + Bean bean; + @Getter + @Setter + private static volatile int called= 0; + + @Getter + private static boolean beanSet = false; + + @Override + public String[] getMapping() { + return new String[] { "/*" }; + } + public Either,Filter> getFilter(){ + + return Either.left(org.springframework.web.filter.DelegatingFilterProxy.class); + + } + public String getName(){ + return "autodiscoveredFilter"; + } + + @Override + public void init(FilterConfig filterConfig) throws ServletException { + + } + + @Override + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + called++; + if(bean!=null) + beanSet =true; + chain.doFilter(request, response); + } + + @Override + public void destroy() { + + + } + + + +} \ No newline at end of file diff --git a/micro-tomcat/src/test/java/app/filter/com/oath/micro/server/Bean.java b/micro-tomcat/src/test/java/app/filter/com/oath/micro/server/Bean.java new file mode 100644 index 000000000..e036a796f --- /dev/null +++ b/micro-tomcat/src/test/java/app/filter/com/oath/micro/server/Bean.java @@ -0,0 +1,8 @@ +package app.filter.com.oath.micro.server; + +import org.springframework.stereotype.Component; + +@Component +public class Bean { + +} diff --git a/micro-tomcat/src/test/java/app/filter/com/oath/micro/server/ConfiguredFilter.java b/micro-tomcat/src/test/java/app/filter/com/oath/micro/server/ConfiguredFilter.java new file mode 100644 index 000000000..aca52ad38 --- /dev/null +++ b/micro-tomcat/src/test/java/app/filter/com/oath/micro/server/ConfiguredFilter.java @@ -0,0 +1,38 @@ +package app.filter.com.oath.micro.server; + +import java.io.IOException; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; + +import lombok.Getter; + +public class ConfiguredFilter implements Filter { + + @Getter + private static volatile int called= 0; + @Override + public void init(FilterConfig filterConfig) throws ServletException { + // TODO Auto-generated method stub + + } + + @Override + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + called++; + chain.doFilter(request, response); + + } + + @Override + public void destroy() { + // TODO Auto-generated method stub + + } + +} diff --git a/micro-tomcat/src/test/java/app/filter/com/oath/micro/server/FilterAppLocalMain.java b/micro-tomcat/src/test/java/app/filter/com/oath/micro/server/FilterAppLocalMain.java new file mode 100644 index 000000000..b650780a2 --- /dev/null +++ b/micro-tomcat/src/test/java/app/filter/com/oath/micro/server/FilterAppLocalMain.java @@ -0,0 +1,20 @@ +package app.filter.com.oath.micro.server; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +import com.oath.micro.server.MicroserverApp; +@Configuration +@ComponentScan(basePackages = { "app.filter.com.aol.micro.server" }) +public class FilterAppLocalMain { + + + + + public static void main(String[] args) throws InterruptedException { + + new MicroserverApp( FilterAppLocalMain.class, () -> "filter-app") + .run(); + } + + } \ No newline at end of file diff --git a/micro-tomcat/src/test/java/app/filter/com/oath/micro/server/FilterRunnerTest.java b/micro-tomcat/src/test/java/app/filter/com/oath/micro/server/FilterRunnerTest.java new file mode 100644 index 000000000..fd26853d3 --- /dev/null +++ b/micro-tomcat/src/test/java/app/filter/com/oath/micro/server/FilterRunnerTest.java @@ -0,0 +1,65 @@ +package app.filter.com.oath.micro.server; + + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.Arrays; +import java.util.Map; +import java.util.concurrent.ExecutionException; + +import javax.servlet.Filter; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.module.ConfigurableModule; +import com.oath.micro.server.testing.RestAgent; +import com.oath.micro.server.utility.HashMapBuilder; + + + +public class FilterRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer() throws InterruptedException{ + Thread.sleep(500); + Map filters = HashMapBuilder.map("/filter-app/status/ping2",new ConfiguredFilter()).build(); + server = new MicroserverApp(ConfigurableModule.builder() + .context("filter-app") + .filters(filters ) + .requestListeners(Arrays.asList(new org.springframework.web.context.request.RequestContextListener())).build()); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void testAutoDiscoveredFilter() throws InterruptedException, ExecutionException{ + AutodiscoveredFilter.setCalled(0); + + assertThat(rest.get("http://localhost:8080/filter-app/status/ping"),is("ok")); + assertThat(AutodiscoveredFilter.getCalled(),is(1)); + assertThat(AutodiscoveredFilter.isBeanSet(),is(true)); + } + @Test + public void testConfiguredFilter() throws InterruptedException, ExecutionException{ + + assertThat(ConfiguredFilter.getCalled(),is(0)); + assertThat(rest.get("http://localhost:8080/filter-app/status/ping2"),is("ok")); + assertThat(ConfiguredFilter.getCalled(),is(1)); + } + + + + +} diff --git a/micro-tomcat/src/test/java/app/filter/com/oath/micro/server/FilterStatusResource.java b/micro-tomcat/src/test/java/app/filter/com/oath/micro/server/FilterStatusResource.java new file mode 100644 index 000000000..c7166c216 --- /dev/null +++ b/micro-tomcat/src/test/java/app/filter/com/oath/micro/server/FilterStatusResource.java @@ -0,0 +1,36 @@ +package app.filter.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.RestResource; + +@Component +@Scope(value=ConfigurableBeanFactory.SCOPE_PROTOTYPE) +@Path("/status") +public class FilterStatusResource implements RestResource { + + @Autowired + private RequestScopeUserInfo info; + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + info.print(); + return "ok"; + } + @GET + @Produces("text/plain") + @Path("/ping2") + public String ping2() { + return "ok"; + } + +} \ No newline at end of file diff --git a/micro-tomcat/src/test/java/app/filter/com/oath/micro/server/RequestScopeUserInfo.java b/micro-tomcat/src/test/java/app/filter/com/oath/micro/server/RequestScopeUserInfo.java new file mode 100644 index 000000000..84c19c3f4 --- /dev/null +++ b/micro-tomcat/src/test/java/app/filter/com/oath/micro/server/RequestScopeUserInfo.java @@ -0,0 +1,20 @@ +package app.filter.com.oath.micro.server; + +import javax.servlet.http.HttpServletRequest; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Scope; +import org.springframework.context.annotation.ScopedProxyMode; +import org.springframework.stereotype.Component; +import org.springframework.web.context.WebApplicationContext; + +@Component +@Scope(value=WebApplicationContext.SCOPE_REQUEST,proxyMode=ScopedProxyMode.TARGET_CLASS) +public class RequestScopeUserInfo { + @Autowired + private HttpServletRequest request; + + public void print(){ + System.out.println(request.getAttribute("oc.info")); + } +} diff --git a/micro-tomcat/src/test/java/app/jackson/custom/com/aol/micro/server/CustomRunnerTest.java b/micro-tomcat/src/test/java/app/jackson/custom/com/aol/micro/server/CustomRunnerTest.java deleted file mode 100644 index e7e14f98f..000000000 --- a/micro-tomcat/src/test/java/app/jackson/custom/com/aol/micro/server/CustomRunnerTest.java +++ /dev/null @@ -1,54 +0,0 @@ -package app.jackson.custom.com.aol.micro.server; - - -import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; - -import java.util.Arrays; -import java.util.concurrent.ExecutionException; - -import org.glassfish.jersey.media.multipart.MultiPartFeature; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.testing.RestAgent; - -@Microserver -public class CustomRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer() throws InterruptedException{ - server = new MicroserverApp(ConfigurableModule - .builder() - .context("simple-app") - .defaultResources(Arrays.asList(MultiPartFeature.class)) - .build()); - Thread.sleep(1000); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - - assertThat(rest.postString("http://localhost:8080/simple-app/status/ping","{\"primitive\":null}").getStatus(),is(500)); - - - } - - - -} diff --git a/micro-tomcat/src/test/java/app/jackson/custom/com/aol/micro/server/CustomStatusResource.java b/micro-tomcat/src/test/java/app/jackson/custom/com/aol/micro/server/CustomStatusResource.java deleted file mode 100644 index d765ba53f..000000000 --- a/micro-tomcat/src/test/java/app/jackson/custom/com/aol/micro/server/CustomStatusResource.java +++ /dev/null @@ -1,20 +0,0 @@ -package app.jackson.custom.com.aol.micro.server; - -import javax.ws.rs.POST; -import javax.ws.rs.Path; - -import com.aol.micro.server.auto.discovery.Rest; - -@Rest -@Path("/status") -public class CustomStatusResource { - - @POST - @Path("/ping") - public String ping(MyEntity entity) { - return "ok"; - - } - - -} \ No newline at end of file diff --git a/micro-tomcat/src/test/java/app/jackson/custom/com/aol/micro/server/MapperExtension.java b/micro-tomcat/src/test/java/app/jackson/custom/com/aol/micro/server/MapperExtension.java deleted file mode 100644 index 3bd1c4e45..000000000 --- a/micro-tomcat/src/test/java/app/jackson/custom/com/aol/micro/server/MapperExtension.java +++ /dev/null @@ -1,18 +0,0 @@ -package app.jackson.custom.com.aol.micro.server; - -import org.springframework.stereotype.Component; - -import com.aol.micro.server.jackson.JacksonMapperConfigurator; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; - -@Component -public class MapperExtension implements JacksonMapperConfigurator { - - @Override - public void accept(ObjectMapper t) { - t.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, true); - - } - -} diff --git a/micro-tomcat/src/test/java/app/jackson/custom/com/aol/micro/server/MyEntity.java b/micro-tomcat/src/test/java/app/jackson/custom/com/aol/micro/server/MyEntity.java deleted file mode 100644 index e62499bff..000000000 --- a/micro-tomcat/src/test/java/app/jackson/custom/com/aol/micro/server/MyEntity.java +++ /dev/null @@ -1,26 +0,0 @@ -package app.jackson.custom.com.aol.micro.server; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -import lombok.Value; - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "") -@XmlRootElement(name = "myentity") -public class MyEntity { - - @XmlElement(name="primitive") - int i; - - public MyEntity(int i) { - super(); - this.i = i; - } - public MyEntity(){ - this.i=-1; - } -} diff --git a/micro-tomcat/src/test/java/app/jackson/custom/com/oath/micro/server/CustomRunnerTest.java b/micro-tomcat/src/test/java/app/jackson/custom/com/oath/micro/server/CustomRunnerTest.java new file mode 100644 index 000000000..c88a0636c --- /dev/null +++ b/micro-tomcat/src/test/java/app/jackson/custom/com/oath/micro/server/CustomRunnerTest.java @@ -0,0 +1,54 @@ +package app.jackson.custom.com.oath.micro.server; + + +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.assertThat; + +import java.util.Arrays; +import java.util.concurrent.ExecutionException; + +import org.glassfish.jersey.media.multipart.MultiPartFeature; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.module.ConfigurableModule; +import com.oath.micro.server.testing.RestAgent; + +@Microserver +public class CustomRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer() throws InterruptedException{ + server = new MicroserverApp(ConfigurableModule + .builder() + .context("simple-app") + .defaultResources(Arrays.asList(MultiPartFeature.class)) + .build()); + Thread.sleep(1000); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + + assertThat(rest.postString("http://localhost:8080/simple-app/status/ping","{\"primitive\":null}").getStatus(),is(500)); + + + } + + + +} diff --git a/micro-tomcat/src/test/java/app/jackson/custom/com/oath/micro/server/CustomStatusResource.java b/micro-tomcat/src/test/java/app/jackson/custom/com/oath/micro/server/CustomStatusResource.java new file mode 100644 index 000000000..6e8a488ba --- /dev/null +++ b/micro-tomcat/src/test/java/app/jackson/custom/com/oath/micro/server/CustomStatusResource.java @@ -0,0 +1,20 @@ +package app.jackson.custom.com.oath.micro.server; + +import javax.ws.rs.POST; +import javax.ws.rs.Path; + +import com.oath.micro.server.auto.discovery.Rest; + +@Rest +@Path("/status") +public class CustomStatusResource { + + @POST + @Path("/ping") + public String ping(MyEntity entity) { + return "ok"; + + } + + +} \ No newline at end of file diff --git a/micro-tomcat/src/test/java/app/jackson/custom/com/oath/micro/server/MapperExtension.java b/micro-tomcat/src/test/java/app/jackson/custom/com/oath/micro/server/MapperExtension.java new file mode 100644 index 000000000..60a50428a --- /dev/null +++ b/micro-tomcat/src/test/java/app/jackson/custom/com/oath/micro/server/MapperExtension.java @@ -0,0 +1,18 @@ +package app.jackson.custom.com.oath.micro.server; + +import org.springframework.stereotype.Component; + +import com.oath.micro.server.jackson.JacksonMapperConfigurator; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; + +@Component +public class MapperExtension implements JacksonMapperConfigurator { + + @Override + public void accept(ObjectMapper t) { + t.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, true); + + } + +} diff --git a/micro-tomcat/src/test/java/app/jackson/custom/com/oath/micro/server/MyEntity.java b/micro-tomcat/src/test/java/app/jackson/custom/com/oath/micro/server/MyEntity.java new file mode 100644 index 000000000..79f8f0b9a --- /dev/null +++ b/micro-tomcat/src/test/java/app/jackson/custom/com/oath/micro/server/MyEntity.java @@ -0,0 +1,24 @@ +package app.jackson.custom.com.oath.micro.server; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "") +@XmlRootElement(name = "myentity") +public class MyEntity { + + @XmlElement(name="primitive") + int i; + + public MyEntity(int i) { + super(); + this.i = i; + } + public MyEntity(){ + this.i=-1; + } +} diff --git a/micro-tomcat/src/test/java/app/jackson/includes/all/com/aol/micro/server/copy/IncludesRunnerTest.java b/micro-tomcat/src/test/java/app/jackson/includes/all/com/aol/micro/server/copy/IncludesRunnerTest.java deleted file mode 100644 index 6edc161bb..000000000 --- a/micro-tomcat/src/test/java/app/jackson/includes/all/com/aol/micro/server/copy/IncludesRunnerTest.java +++ /dev/null @@ -1,57 +0,0 @@ -package app.jackson.includes.all.com.aol.micro.server.copy; - - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.Arrays; -import java.util.concurrent.ExecutionException; - -import org.glassfish.jersey.media.multipart.MultiPartFeature; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.testing.RestAgent; - -@Microserver(properties={"jackson.serialization","ALWAYS"}) -public class IncludesRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer() throws InterruptedException{ - Thread.sleep(5000); - server = new MicroserverApp(ConfigurableModule - .builder() - .context("simple-app") - .defaultResources(Arrays.asList(MultiPartFeature.class)) - .build()); - - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - - - assertThat(rest.getJson("http://localhost:8080/simple-app/status/ping"),is("{\"primitive\":null}")); - - - } - - - -} diff --git a/micro-tomcat/src/test/java/app/jackson/includes/all/com/aol/micro/server/copy/IncludesStatusResource.java b/micro-tomcat/src/test/java/app/jackson/includes/all/com/aol/micro/server/copy/IncludesStatusResource.java deleted file mode 100644 index 566d503b9..000000000 --- a/micro-tomcat/src/test/java/app/jackson/includes/all/com/aol/micro/server/copy/IncludesStatusResource.java +++ /dev/null @@ -1,22 +0,0 @@ -package app.jackson.includes.all.com.aol.micro.server.copy; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import com.aol.micro.server.auto.discovery.Rest; - -@Rest -@Path("/status") -public class IncludesStatusResource { - - @GET - @Path("/ping") - @Produces("application/json") - public MyEntity ping() { - return new MyEntity(); - - } - - -} \ No newline at end of file diff --git a/micro-tomcat/src/test/java/app/jackson/includes/all/com/aol/micro/server/copy/MyEntity.java b/micro-tomcat/src/test/java/app/jackson/includes/all/com/aol/micro/server/copy/MyEntity.java deleted file mode 100644 index e2c6b02ba..000000000 --- a/micro-tomcat/src/test/java/app/jackson/includes/all/com/aol/micro/server/copy/MyEntity.java +++ /dev/null @@ -1,26 +0,0 @@ -package app.jackson.includes.all.com.aol.micro.server.copy; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -import lombok.Value; - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "") -@XmlRootElement(name = "myentity") -public class MyEntity { - - @XmlElement(name="primitive") - Integer i = null; - - public MyEntity(int i) { - super(); - this.i = i; - } - public MyEntity(){ - this.i=null; - } -} diff --git a/micro-tomcat/src/test/java/app/jackson/includes/all/com/oath/micro/server/copy/IncludesRunnerTest.java b/micro-tomcat/src/test/java/app/jackson/includes/all/com/oath/micro/server/copy/IncludesRunnerTest.java new file mode 100644 index 000000000..05581a3fa --- /dev/null +++ b/micro-tomcat/src/test/java/app/jackson/includes/all/com/oath/micro/server/copy/IncludesRunnerTest.java @@ -0,0 +1,56 @@ +package app.jackson.includes.all.com.oath.micro.server.copy; + + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.Arrays; +import java.util.concurrent.ExecutionException; + +import org.glassfish.jersey.media.multipart.MultiPartFeature; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.module.ConfigurableModule; +import com.oath.micro.server.testing.RestAgent; + +@Microserver(properties={"jackson.serialization","ALWAYS"}) +public class IncludesRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer() throws InterruptedException{ + Thread.sleep(5000); + server = new MicroserverApp(ConfigurableModule + .builder() + .context("simple-app") + .defaultResources(Arrays.asList(MultiPartFeature.class)) + .build()); + + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + + + assertThat(rest.getJson("http://localhost:8080/simple-app/status/ping"),is("{\"primitive\":null}")); + + + } + + + +} diff --git a/micro-tomcat/src/test/java/app/jackson/includes/all/com/oath/micro/server/copy/IncludesStatusResource.java b/micro-tomcat/src/test/java/app/jackson/includes/all/com/oath/micro/server/copy/IncludesStatusResource.java new file mode 100644 index 000000000..bc0d8f3bb --- /dev/null +++ b/micro-tomcat/src/test/java/app/jackson/includes/all/com/oath/micro/server/copy/IncludesStatusResource.java @@ -0,0 +1,22 @@ +package app.jackson.includes.all.com.oath.micro.server.copy; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import com.oath.micro.server.auto.discovery.Rest; + +@Rest +@Path("/status") +public class IncludesStatusResource { + + @GET + @Path("/ping") + @Produces("application/json") + public MyEntity ping() { + return new MyEntity(); + + } + + +} \ No newline at end of file diff --git a/micro-tomcat/src/test/java/app/jackson/includes/all/com/oath/micro/server/copy/MyEntity.java b/micro-tomcat/src/test/java/app/jackson/includes/all/com/oath/micro/server/copy/MyEntity.java new file mode 100644 index 000000000..2b28c5d5b --- /dev/null +++ b/micro-tomcat/src/test/java/app/jackson/includes/all/com/oath/micro/server/copy/MyEntity.java @@ -0,0 +1,24 @@ +package app.jackson.includes.all.com.oath.micro.server.copy; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "") +@XmlRootElement(name = "myentity") +public class MyEntity { + + @XmlElement(name="primitive") + Integer i = null; + + public MyEntity(int i) { + super(); + this.i = i; + } + public MyEntity(){ + this.i=null; + } +} diff --git a/micro-tomcat/src/test/java/app/jackson/includes/nonnull/com/aol/micro/server/IncludesRunnerTest.java b/micro-tomcat/src/test/java/app/jackson/includes/nonnull/com/aol/micro/server/IncludesRunnerTest.java deleted file mode 100644 index a311d0a80..000000000 --- a/micro-tomcat/src/test/java/app/jackson/includes/nonnull/com/aol/micro/server/IncludesRunnerTest.java +++ /dev/null @@ -1,57 +0,0 @@ -package app.jackson.includes.nonnull.com.aol.micro.server; - - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.Arrays; -import java.util.concurrent.ExecutionException; - -import javax.ws.rs.core.Response; - -import org.glassfish.jersey.media.multipart.MultiPartFeature; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.testing.RestAgent; - -@Microserver -public class IncludesRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer() throws InterruptedException{ - server = new MicroserverApp(ConfigurableModule - .builder() - .context("simple-app") - .defaultResources(Arrays.asList(MultiPartFeature.class)) - .build()); - Thread.sleep(5000); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - - - assertThat(rest.getJson("http://localhost:8080/simple-app/status/ping"),is("{}")); - - - } - - - -} diff --git a/micro-tomcat/src/test/java/app/jackson/includes/nonnull/com/aol/micro/server/IncludesStatusResource.java b/micro-tomcat/src/test/java/app/jackson/includes/nonnull/com/aol/micro/server/IncludesStatusResource.java deleted file mode 100644 index f3a9b74b4..000000000 --- a/micro-tomcat/src/test/java/app/jackson/includes/nonnull/com/aol/micro/server/IncludesStatusResource.java +++ /dev/null @@ -1,22 +0,0 @@ -package app.jackson.includes.nonnull.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import com.aol.micro.server.auto.discovery.Rest; - -@Rest -@Path("/status") -public class IncludesStatusResource { - - @GET - @Path("/ping") - @Produces("application/json") - public MyEntity ping() { - return new MyEntity(); - - } - - -} \ No newline at end of file diff --git a/micro-tomcat/src/test/java/app/jackson/includes/nonnull/com/aol/micro/server/MyEntity.java b/micro-tomcat/src/test/java/app/jackson/includes/nonnull/com/aol/micro/server/MyEntity.java deleted file mode 100644 index 3caa39982..000000000 --- a/micro-tomcat/src/test/java/app/jackson/includes/nonnull/com/aol/micro/server/MyEntity.java +++ /dev/null @@ -1,26 +0,0 @@ -package app.jackson.includes.nonnull.com.aol.micro.server; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -import lombok.Value; - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "") -@XmlRootElement(name = "myentity") -public class MyEntity { - - @XmlElement(name="primitive") - Integer i = null; - - public MyEntity(int i) { - super(); - this.i = i; - } - public MyEntity(){ - this.i=null; - } -} diff --git a/micro-tomcat/src/test/java/app/jackson/includes/nonnull/com/oath/micro/server/IncludesRunnerTest.java b/micro-tomcat/src/test/java/app/jackson/includes/nonnull/com/oath/micro/server/IncludesRunnerTest.java new file mode 100644 index 000000000..89130e833 --- /dev/null +++ b/micro-tomcat/src/test/java/app/jackson/includes/nonnull/com/oath/micro/server/IncludesRunnerTest.java @@ -0,0 +1,55 @@ +package app.jackson.includes.nonnull.com.oath.micro.server; + + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.Arrays; +import java.util.concurrent.ExecutionException; + +import org.glassfish.jersey.media.multipart.MultiPartFeature; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.module.ConfigurableModule; +import com.oath.micro.server.testing.RestAgent; + +@Microserver +public class IncludesRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer() throws InterruptedException{ + server = new MicroserverApp(ConfigurableModule + .builder() + .context("simple-app") + .defaultResources(Arrays.asList(MultiPartFeature.class)) + .build()); + Thread.sleep(5000); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + + + assertThat(rest.getJson("http://localhost:8080/simple-app/status/ping"),is("{}")); + + + } + + + +} diff --git a/micro-tomcat/src/test/java/app/jackson/includes/nonnull/com/oath/micro/server/IncludesStatusResource.java b/micro-tomcat/src/test/java/app/jackson/includes/nonnull/com/oath/micro/server/IncludesStatusResource.java new file mode 100644 index 000000000..477b68744 --- /dev/null +++ b/micro-tomcat/src/test/java/app/jackson/includes/nonnull/com/oath/micro/server/IncludesStatusResource.java @@ -0,0 +1,22 @@ +package app.jackson.includes.nonnull.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import com.oath.micro.server.auto.discovery.Rest; + +@Rest +@Path("/status") +public class IncludesStatusResource { + + @GET + @Path("/ping") + @Produces("application/json") + public MyEntity ping() { + return new MyEntity(); + + } + + +} \ No newline at end of file diff --git a/micro-tomcat/src/test/java/app/jackson/includes/nonnull/com/oath/micro/server/MyEntity.java b/micro-tomcat/src/test/java/app/jackson/includes/nonnull/com/oath/micro/server/MyEntity.java new file mode 100644 index 000000000..6671f20d4 --- /dev/null +++ b/micro-tomcat/src/test/java/app/jackson/includes/nonnull/com/oath/micro/server/MyEntity.java @@ -0,0 +1,24 @@ +package app.jackson.includes.nonnull.com.oath.micro.server; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "") +@XmlRootElement(name = "myentity") +public class MyEntity { + + @XmlElement(name="primitive") + Integer i = null; + + public MyEntity(int i) { + super(); + this.i = i; + } + public MyEntity(){ + this.i=null; + } +} diff --git a/micro-tomcat/src/test/java/app/listeners/com/aol/micro/server/AutodiscoveredListener.java b/micro-tomcat/src/test/java/app/listeners/com/aol/micro/server/AutodiscoveredListener.java deleted file mode 100644 index bff7cbdc8..000000000 --- a/micro-tomcat/src/test/java/app/listeners/com/aol/micro/server/AutodiscoveredListener.java +++ /dev/null @@ -1,35 +0,0 @@ -package app.listeners.com.aol.micro.server; - -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; - -import lombok.Getter; - -import org.springframework.stereotype.Component; - -@Component -public class AutodiscoveredListener implements ServletContextListener { - - @Getter - private static volatile int called= 0; - - @Override - public void contextInitialized(ServletContextEvent sce) { - called ++; - - } - - @Override - public void contextDestroyed(ServletContextEvent sce) { - - - } - - - - - - - - -} \ No newline at end of file diff --git a/micro-tomcat/src/test/java/app/listeners/com/aol/micro/server/ConfiguredListener.java b/micro-tomcat/src/test/java/app/listeners/com/aol/micro/server/ConfiguredListener.java deleted file mode 100644 index d15dcb76e..000000000 --- a/micro-tomcat/src/test/java/app/listeners/com/aol/micro/server/ConfiguredListener.java +++ /dev/null @@ -1,25 +0,0 @@ -package app.listeners.com.aol.micro.server; - -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; - -import lombok.Getter; - -public class ConfiguredListener implements ServletContextListener { - - @Getter - private static volatile int called= 0; - - @Override - public void contextInitialized(ServletContextEvent sce) { - called ++; - - } - - @Override - public void contextDestroyed(ServletContextEvent sce) { - - - } - -} \ No newline at end of file diff --git a/micro-tomcat/src/test/java/app/listeners/com/aol/micro/server/ListenerRunnerTest.java b/micro-tomcat/src/test/java/app/listeners/com/aol/micro/server/ListenerRunnerTest.java deleted file mode 100644 index 4f8d7ab69..000000000 --- a/micro-tomcat/src/test/java/app/listeners/com/aol/micro/server/ListenerRunnerTest.java +++ /dev/null @@ -1,55 +0,0 @@ -package app.listeners.com.aol.micro.server; - - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.ExecutionException; - -import javax.servlet.ServletContextListener; - - - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.testing.RestAgent; - - -@Microserver -public class ListenerRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer(){ - List listeners = Arrays.asList(new ConfiguredListener()); - server = new MicroserverApp( ListenerRunnerTest.class, ConfigurableModule.builder().context("listener-app").listeners(listeners ).build()); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void testListeners() throws InterruptedException, ExecutionException{ - - assertThat(AutodiscoveredListener.getCalled(),is(1)); - assertThat(ConfiguredListener.getCalled(),is(1)); - } - - - - - -} diff --git a/micro-tomcat/src/test/java/app/listeners/com/oath/micro/server/AutodiscoveredListener.java b/micro-tomcat/src/test/java/app/listeners/com/oath/micro/server/AutodiscoveredListener.java new file mode 100644 index 000000000..a3dfdff21 --- /dev/null +++ b/micro-tomcat/src/test/java/app/listeners/com/oath/micro/server/AutodiscoveredListener.java @@ -0,0 +1,35 @@ +package app.listeners.com.oath.micro.server; + +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; + +import lombok.Getter; + +import org.springframework.stereotype.Component; + +@Component +public class AutodiscoveredListener implements ServletContextListener { + + @Getter + private static volatile int called= 0; + + @Override + public void contextInitialized(ServletContextEvent sce) { + called ++; + + } + + @Override + public void contextDestroyed(ServletContextEvent sce) { + + + } + + + + + + + + +} \ No newline at end of file diff --git a/micro-tomcat/src/test/java/app/listeners/com/oath/micro/server/ConfiguredListener.java b/micro-tomcat/src/test/java/app/listeners/com/oath/micro/server/ConfiguredListener.java new file mode 100644 index 000000000..86a7cd34b --- /dev/null +++ b/micro-tomcat/src/test/java/app/listeners/com/oath/micro/server/ConfiguredListener.java @@ -0,0 +1,25 @@ +package app.listeners.com.oath.micro.server; + +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; + +import lombok.Getter; + +public class ConfiguredListener implements ServletContextListener { + + @Getter + private static volatile int called= 0; + + @Override + public void contextInitialized(ServletContextEvent sce) { + called ++; + + } + + @Override + public void contextDestroyed(ServletContextEvent sce) { + + + } + +} \ No newline at end of file diff --git a/micro-tomcat/src/test/java/app/listeners/com/oath/micro/server/ListenerRunnerTest.java b/micro-tomcat/src/test/java/app/listeners/com/oath/micro/server/ListenerRunnerTest.java new file mode 100644 index 000000000..fa0222a76 --- /dev/null +++ b/micro-tomcat/src/test/java/app/listeners/com/oath/micro/server/ListenerRunnerTest.java @@ -0,0 +1,55 @@ +package app.listeners.com.oath.micro.server; + + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.ExecutionException; + +import javax.servlet.ServletContextListener; + + + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.module.ConfigurableModule; +import com.oath.micro.server.testing.RestAgent; + + +@Microserver +public class ListenerRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer(){ + List listeners = Arrays.asList(new ConfiguredListener()); + server = new MicroserverApp( ListenerRunnerTest.class, ConfigurableModule.builder().context("listener-app").listeners(listeners ).build()); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void testListeners() throws InterruptedException, ExecutionException{ + + assertThat(AutodiscoveredListener.getCalled(),is(1)); + assertThat(ConfiguredListener.getCalled(),is(1)); + } + + + + + +} diff --git a/micro-tomcat/src/test/java/app/minimal/com/aol/micro/server/MinimalClassTest.java b/micro-tomcat/src/test/java/app/minimal/com/aol/micro/server/MinimalClassTest.java deleted file mode 100644 index 22cd649cd..000000000 --- a/micro-tomcat/src/test/java/app/minimal/com/aol/micro/server/MinimalClassTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package app.minimal.com.aol.micro.server; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.auto.discovery.RestResource; -import com.aol.micro.server.testing.RestAgent; - -@Rest -@Path("/single") -public class MinimalClassTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - - @Before - public void startServer() { - - server = new MicroserverApp( - () -> "minimal-app"); - server.start(); - - } - - @After - public void stopServer() { - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException { - - Thread.sleep(500l); - assertThat(rest.get("http://localhost:8080/minimal-app/single/ping"), is("ok")); - - } - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "ok"; - } - -} \ No newline at end of file diff --git a/micro-tomcat/src/test/java/app/minimal/com/oath/micro/server/MinimalClassTest.java b/micro-tomcat/src/test/java/app/minimal/com/oath/micro/server/MinimalClassTest.java new file mode 100644 index 000000000..6640ecea0 --- /dev/null +++ b/micro-tomcat/src/test/java/app/minimal/com/oath/micro/server/MinimalClassTest.java @@ -0,0 +1,57 @@ +package app.minimal.com.oath.micro.server; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.auto.discovery.Rest; +import com.oath.micro.server.testing.RestAgent; + +@Rest +@Path("/single") +public class MinimalClassTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + + @Before + public void startServer() { + + server = new MicroserverApp( + () -> "minimal-app"); + server.start(); + + } + + @After + public void stopServer() { + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException { + + Thread.sleep(500l); + assertThat(rest.get("http://localhost:8080/minimal-app/single/ping"), is("ok")); + + } + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "ok"; + } + +} \ No newline at end of file diff --git a/micro-tomcat/src/test/java/app/noanno/com/aol/micro/server/copy/NoAnnoRunnerTest.java b/micro-tomcat/src/test/java/app/noanno/com/aol/micro/server/copy/NoAnnoRunnerTest.java deleted file mode 100644 index 92abed060..000000000 --- a/micro-tomcat/src/test/java/app/noanno/com/aol/micro/server/copy/NoAnnoRunnerTest.java +++ /dev/null @@ -1,49 +0,0 @@ -package app.noanno.com.aol.micro.server.copy; - - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.testing.RestAgent; - - -public class NoAnnoRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer() throws InterruptedException{ - - server = new MicroserverApp(()-> "simple-app"); - Thread.sleep(1000); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - - - assertThat(rest.get("http://localhost:8080/simple-app/status/ping"),is("ok")); - - - } - - - -} diff --git a/micro-tomcat/src/test/java/app/noanno/com/aol/micro/server/copy/NoAnnoStatusResource.java b/micro-tomcat/src/test/java/app/noanno/com/aol/micro/server/copy/NoAnnoStatusResource.java deleted file mode 100644 index 8a3f5efaa..000000000 --- a/micro-tomcat/src/test/java/app/noanno/com/aol/micro/server/copy/NoAnnoStatusResource.java +++ /dev/null @@ -1,24 +0,0 @@ -package app.noanno.com.aol.micro.server.copy; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import com.aol.micro.server.auto.discovery.Rest; - -@Rest -@Path("/status") -public class NoAnnoStatusResource { - - - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - - return "ok"; - } - - -} \ No newline at end of file diff --git a/micro-tomcat/src/test/java/app/noanno/com/aol/micro/server/copy/SimpleApp.java b/micro-tomcat/src/test/java/app/noanno/com/aol/micro/server/copy/SimpleApp.java deleted file mode 100644 index 5fb7e2ca3..000000000 --- a/micro-tomcat/src/test/java/app/noanno/com/aol/micro/server/copy/SimpleApp.java +++ /dev/null @@ -1,12 +0,0 @@ -package app.noanno.com.aol.micro.server.copy; - -import com.aol.micro.server.MicroserverApp; - -public class SimpleApp { - - public static void main(String[] args){ - new MicroserverApp(()-> "simple-app").run(); - } - - -} diff --git a/micro-tomcat/src/test/java/app/noanno/com/oath/micro/server/copy/NoAnnoRunnerTest.java b/micro-tomcat/src/test/java/app/noanno/com/oath/micro/server/copy/NoAnnoRunnerTest.java new file mode 100644 index 000000000..b476e2791 --- /dev/null +++ b/micro-tomcat/src/test/java/app/noanno/com/oath/micro/server/copy/NoAnnoRunnerTest.java @@ -0,0 +1,48 @@ +package app.noanno.com.oath.micro.server.copy; + + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.testing.RestAgent; + + +public class NoAnnoRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer() throws InterruptedException{ + + server = new MicroserverApp(()-> "simple-app"); + Thread.sleep(1000); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + + + assertThat(rest.get("http://localhost:8080/simple-app/status/ping"),is("ok")); + + + } + + + +} diff --git a/micro-tomcat/src/test/java/app/noanno/com/oath/micro/server/copy/NoAnnoStatusResource.java b/micro-tomcat/src/test/java/app/noanno/com/oath/micro/server/copy/NoAnnoStatusResource.java new file mode 100644 index 000000000..11a42968e --- /dev/null +++ b/micro-tomcat/src/test/java/app/noanno/com/oath/micro/server/copy/NoAnnoStatusResource.java @@ -0,0 +1,24 @@ +package app.noanno.com.oath.micro.server.copy; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import com.oath.micro.server.auto.discovery.Rest; + +@Rest +@Path("/status") +public class NoAnnoStatusResource { + + + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + + return "ok"; + } + + +} \ No newline at end of file diff --git a/micro-tomcat/src/test/java/app/noanno/com/oath/micro/server/copy/SimpleApp.java b/micro-tomcat/src/test/java/app/noanno/com/oath/micro/server/copy/SimpleApp.java new file mode 100644 index 000000000..646004a31 --- /dev/null +++ b/micro-tomcat/src/test/java/app/noanno/com/oath/micro/server/copy/SimpleApp.java @@ -0,0 +1,12 @@ +package app.noanno.com.oath.micro.server.copy; + +import com.oath.micro.server.MicroserverApp; + +public class SimpleApp { + + public static void main(String[] args){ + new MicroserverApp(()-> "simple-app").run(); + } + + +} diff --git a/micro-tomcat/src/test/java/app/servlet/com/aol/micro/server/AppRunnerLocalMain.java b/micro-tomcat/src/test/java/app/servlet/com/aol/micro/server/AppRunnerLocalMain.java deleted file mode 100644 index b447491a1..000000000 --- a/micro-tomcat/src/test/java/app/servlet/com/aol/micro/server/AppRunnerLocalMain.java +++ /dev/null @@ -1,20 +0,0 @@ -package app.servlet.com.aol.micro.server; - - -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; - -import com.aol.micro.server.MicroserverApp; - -@Configuration -@ComponentScan(basePackages = { "app.servlet.com.aol.micro.server" }) -public class AppRunnerLocalMain { - - - public static void main(String[] args) throws InterruptedException { - - new MicroserverApp( AppRunnerLocalMain.class, () -> "test-app") - .run(); - } - -} diff --git a/micro-tomcat/src/test/java/app/servlet/com/aol/micro/server/AutodiscoveredServlet.java b/micro-tomcat/src/test/java/app/servlet/com/aol/micro/server/AutodiscoveredServlet.java deleted file mode 100644 index 3e64043bf..000000000 --- a/micro-tomcat/src/test/java/app/servlet/com/aol/micro/server/AutodiscoveredServlet.java +++ /dev/null @@ -1,30 +0,0 @@ -package app.servlet.com.aol.micro.server; - -import java.io.IOException; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.AutoServletConfiguration; - -@Component -public class AutodiscoveredServlet extends HttpServlet implements AutoServletConfiguration { - - @Override - public String[] getMapping() { - return new String[] { "/servlet" }; - } - - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) - throws ServletException, IOException { - - resp.setContentType("text/html"); - resp.getWriter().write("hello world"); - } - -} diff --git a/micro-tomcat/src/test/java/app/servlet/com/aol/micro/server/ConfiguredServlet.java b/micro-tomcat/src/test/java/app/servlet/com/aol/micro/server/ConfiguredServlet.java deleted file mode 100644 index 92577a92e..000000000 --- a/micro-tomcat/src/test/java/app/servlet/com/aol/micro/server/ConfiguredServlet.java +++ /dev/null @@ -1,24 +0,0 @@ -package app.servlet.com.aol.micro.server; - -import java.io.IOException; - -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -public class ConfiguredServlet extends HttpServlet { - - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) - throws ServletException, IOException { - resp.setContentType("text/html"); - resp.getWriter().write("configured servlet"); - } - - - -} diff --git a/micro-tomcat/src/test/java/app/servlet/com/aol/micro/server/ServletRunnerTest.java b/micro-tomcat/src/test/java/app/servlet/com/aol/micro/server/ServletRunnerTest.java deleted file mode 100644 index 40ea43478..000000000 --- a/micro-tomcat/src/test/java/app/servlet/com/aol/micro/server/ServletRunnerTest.java +++ /dev/null @@ -1,53 +0,0 @@ -package app.servlet.com.aol.micro.server; - - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.ExecutionException; - -import javax.servlet.Servlet; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.testing.RestAgent; - -public class ServletRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer() throws InterruptedException{ - Map servlets = new HashMap<>(); - servlets.put("/configured", new ConfiguredServlet()); - server = new MicroserverApp( AppRunnerLocalMain.class, ConfigurableModule.builder().context("test-app").servlets(servlets ).build()); - Thread.sleep(1000); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - assertThat(rest.get("http://localhost:8080/test-app/servlet/ping"),is("ok")); - assertThat(rest.get("http://localhost:8080/servlet"),is("hello world")); - assertThat(rest.get("http://localhost:8080/configured"),is("configured servlet")); - - } - - - - -} diff --git a/micro-tomcat/src/test/java/app/servlet/com/aol/micro/server/ServletStatusResource.java b/micro-tomcat/src/test/java/app/servlet/com/aol/micro/server/ServletStatusResource.java deleted file mode 100644 index 890a64679..000000000 --- a/micro-tomcat/src/test/java/app/servlet/com/aol/micro/server/ServletStatusResource.java +++ /dev/null @@ -1,22 +0,0 @@ -package app.servlet.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.RestResource; - -@Component -@Path("/servlet") -public class ServletStatusResource implements RestResource { - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "ok"; - } - -} \ No newline at end of file diff --git a/micro-tomcat/src/test/java/app/servlet/com/oath/micro/server/AppRunnerLocalMain.java b/micro-tomcat/src/test/java/app/servlet/com/oath/micro/server/AppRunnerLocalMain.java new file mode 100644 index 000000000..065973f62 --- /dev/null +++ b/micro-tomcat/src/test/java/app/servlet/com/oath/micro/server/AppRunnerLocalMain.java @@ -0,0 +1,20 @@ +package app.servlet.com.oath.micro.server; + + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +import com.oath.micro.server.MicroserverApp; + +@Configuration +@ComponentScan(basePackages = { "app.servlet.com.aol.micro.server" }) +public class AppRunnerLocalMain { + + + public static void main(String[] args) throws InterruptedException { + + new MicroserverApp( AppRunnerLocalMain.class, () -> "test-app") + .run(); + } + +} diff --git a/micro-tomcat/src/test/java/app/servlet/com/oath/micro/server/AutodiscoveredServlet.java b/micro-tomcat/src/test/java/app/servlet/com/oath/micro/server/AutodiscoveredServlet.java new file mode 100644 index 000000000..66cbfd59c --- /dev/null +++ b/micro-tomcat/src/test/java/app/servlet/com/oath/micro/server/AutodiscoveredServlet.java @@ -0,0 +1,30 @@ +package app.servlet.com.oath.micro.server; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.AutoServletConfiguration; + +@Component +public class AutodiscoveredServlet extends HttpServlet implements AutoServletConfiguration { + + @Override + public String[] getMapping() { + return new String[] { "/servlet" }; + } + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + + resp.setContentType("text/html"); + resp.getWriter().write("hello world"); + } + +} diff --git a/micro-tomcat/src/test/java/app/servlet/com/oath/micro/server/ConfiguredServlet.java b/micro-tomcat/src/test/java/app/servlet/com/oath/micro/server/ConfiguredServlet.java new file mode 100644 index 000000000..65de82291 --- /dev/null +++ b/micro-tomcat/src/test/java/app/servlet/com/oath/micro/server/ConfiguredServlet.java @@ -0,0 +1,21 @@ +package app.servlet.com.oath.micro.server; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class ConfiguredServlet extends HttpServlet { + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + resp.setContentType("text/html"); + resp.getWriter().write("configured servlet"); + } + + + +} diff --git a/micro-tomcat/src/test/java/app/servlet/com/oath/micro/server/ServletRunnerTest.java b/micro-tomcat/src/test/java/app/servlet/com/oath/micro/server/ServletRunnerTest.java new file mode 100644 index 000000000..0829b9f05 --- /dev/null +++ b/micro-tomcat/src/test/java/app/servlet/com/oath/micro/server/ServletRunnerTest.java @@ -0,0 +1,53 @@ +package app.servlet.com.oath.micro.server; + + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ExecutionException; + +import javax.servlet.Servlet; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.module.ConfigurableModule; +import com.oath.micro.server.testing.RestAgent; + +public class ServletRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer() throws InterruptedException{ + Map servlets = new HashMap<>(); + servlets.put("/configured", new ConfiguredServlet()); + server = new MicroserverApp( AppRunnerLocalMain.class, ConfigurableModule.builder().context("test-app").servlets(servlets ).build()); + Thread.sleep(1000); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + assertThat(rest.get("http://localhost:8080/test-app/servlet/ping"),is("ok")); + assertThat(rest.get("http://localhost:8080/servlet"),is("hello world")); + assertThat(rest.get("http://localhost:8080/configured"),is("configured servlet")); + + } + + + + +} diff --git a/micro-tomcat/src/test/java/app/servlet/com/oath/micro/server/ServletStatusResource.java b/micro-tomcat/src/test/java/app/servlet/com/oath/micro/server/ServletStatusResource.java new file mode 100644 index 000000000..6d86eeb84 --- /dev/null +++ b/micro-tomcat/src/test/java/app/servlet/com/oath/micro/server/ServletStatusResource.java @@ -0,0 +1,22 @@ +package app.servlet.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.RestResource; + +@Component +@Path("/servlet") +public class ServletStatusResource implements RestResource { + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "ok"; + } + +} \ No newline at end of file diff --git a/micro-tomcat/src/test/java/app/simple/com/aol/micro/server/SimpleApp.java b/micro-tomcat/src/test/java/app/simple/com/aol/micro/server/SimpleApp.java deleted file mode 100644 index 700a2c778..000000000 --- a/micro-tomcat/src/test/java/app/simple/com/aol/micro/server/SimpleApp.java +++ /dev/null @@ -1,18 +0,0 @@ -package app.simple.com.aol.micro.server; - -import java.util.Arrays; - -import org.glassfish.jersey.media.multipart.MultiPartFeature; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.module.ConfigurableModule; - -public class SimpleApp { - - public static void main(String[] args){ - - new MicroserverApp(()-> "simple-app").run(); - } - - -} diff --git a/micro-tomcat/src/test/java/app/simple/com/aol/micro/server/SimpleRunnerTest.java b/micro-tomcat/src/test/java/app/simple/com/aol/micro/server/SimpleRunnerTest.java deleted file mode 100644 index 57bc0e1ef..000000000 --- a/micro-tomcat/src/test/java/app/simple/com/aol/micro/server/SimpleRunnerTest.java +++ /dev/null @@ -1,55 +0,0 @@ -package app.simple.com.aol.micro.server; - - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.Arrays; -import java.util.concurrent.ExecutionException; - -import org.glassfish.jersey.media.multipart.MultiPartFeature; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.testing.RestAgent; - -@Microserver -public class SimpleRunnerTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer() throws InterruptedException{ - server = new MicroserverApp(ConfigurableModule - .builder() - .context("simple-app") - .defaultResources(Arrays.asList(MultiPartFeature.class)) - .build()); - Thread.sleep(1000); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - - - assertThat(rest.get("http://localhost:8080/simple-app/status/ping"),is("ok")); - - - } - - - -} diff --git a/micro-tomcat/src/test/java/app/simple/com/aol/micro/server/SimpleStatusResource.java b/micro-tomcat/src/test/java/app/simple/com/aol/micro/server/SimpleStatusResource.java deleted file mode 100644 index 07b6a5610..000000000 --- a/micro-tomcat/src/test/java/app/simple/com/aol/micro/server/SimpleStatusResource.java +++ /dev/null @@ -1,40 +0,0 @@ -package app.simple.com.aol.micro.server; - -import java.io.InputStream; - -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; - -import org.glassfish.jersey.media.multipart.FormDataContentDisposition; -import org.glassfish.jersey.media.multipart.FormDataParam; - -import com.aol.micro.server.auto.discovery.Rest; - -@Rest -@Path("/status") -public class SimpleStatusResource { - - - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - - return "ok"; - } - - @POST - @Consumes(MediaType.MULTIPART_FORM_DATA) - @Produces(MediaType.TEXT_PLAIN) - @Path("/file") - public String create(@FormDataParam("file") InputStream fileInputStream, - @FormDataParam("file") FormDataContentDisposition contentDispositionHeader) { - - return "done"; - } -} \ No newline at end of file diff --git a/micro-tomcat/src/test/java/app/simple/com/oath/micro/server/SimpleApp.java b/micro-tomcat/src/test/java/app/simple/com/oath/micro/server/SimpleApp.java new file mode 100644 index 000000000..e82a92291 --- /dev/null +++ b/micro-tomcat/src/test/java/app/simple/com/oath/micro/server/SimpleApp.java @@ -0,0 +1,13 @@ +package app.simple.com.oath.micro.server; + +import com.oath.micro.server.MicroserverApp; + +public class SimpleApp { + + public static void main(String[] args){ + + new MicroserverApp(()-> "simple-app").run(); + } + + +} diff --git a/micro-tomcat/src/test/java/app/simple/com/oath/micro/server/SimpleRunnerTest.java b/micro-tomcat/src/test/java/app/simple/com/oath/micro/server/SimpleRunnerTest.java new file mode 100644 index 000000000..504b5199e --- /dev/null +++ b/micro-tomcat/src/test/java/app/simple/com/oath/micro/server/SimpleRunnerTest.java @@ -0,0 +1,55 @@ +package app.simple.com.oath.micro.server; + + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.Arrays; +import java.util.concurrent.ExecutionException; + +import org.glassfish.jersey.media.multipart.MultiPartFeature; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.module.ConfigurableModule; +import com.oath.micro.server.testing.RestAgent; + +@Microserver +public class SimpleRunnerTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer() throws InterruptedException{ + server = new MicroserverApp(ConfigurableModule + .builder() + .context("simple-app") + .defaultResources(Arrays.asList(MultiPartFeature.class)) + .build()); + Thread.sleep(1000); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + + + assertThat(rest.get("http://localhost:8080/simple-app/status/ping"),is("ok")); + + + } + + + +} diff --git a/micro-tomcat/src/test/java/app/simple/com/oath/micro/server/SimpleStatusResource.java b/micro-tomcat/src/test/java/app/simple/com/oath/micro/server/SimpleStatusResource.java new file mode 100644 index 000000000..7be280bdf --- /dev/null +++ b/micro-tomcat/src/test/java/app/simple/com/oath/micro/server/SimpleStatusResource.java @@ -0,0 +1,40 @@ +package app.simple.com.oath.micro.server; + +import java.io.InputStream; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +import org.glassfish.jersey.media.multipart.FormDataContentDisposition; +import org.glassfish.jersey.media.multipart.FormDataParam; + +import com.oath.micro.server.auto.discovery.Rest; + +@Rest +@Path("/status") +public class SimpleStatusResource { + + + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + + return "ok"; + } + + @POST + @Consumes(MediaType.MULTIPART_FORM_DATA) + @Produces(MediaType.TEXT_PLAIN) + @Path("/file") + public String create(@FormDataParam("file") InputStream fileInputStream, + @FormDataParam("file") FormDataContentDisposition contentDispositionHeader) { + + return "done"; + } +} \ No newline at end of file diff --git a/micro-tomcat/src/test/java/app/single/com/aol/micro/server/SingleClassTest.java b/micro-tomcat/src/test/java/app/single/com/aol/micro/server/SingleClassTest.java deleted file mode 100644 index 4839e9fff..000000000 --- a/micro-tomcat/src/test/java/app/single/com/aol/micro/server/SingleClassTest.java +++ /dev/null @@ -1,59 +0,0 @@ -package app.single.com.aol.micro.server; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.RestResource; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.testing.RestAgent; - -@Microserver -@Path("/single") -public class SingleClassTest implements RestResource{ - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - @Before - public void startServer() throws InterruptedException{ - - server = new MicroserverApp( SingleClassTest.class, ()-> "simple-app"); - Thread.sleep(1000); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - - - assertThat(rest.get("http://localhost:8080/simple-app/single/ping"),is("ok")); - - } - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "ok"; - } - - -} \ No newline at end of file diff --git a/micro-tomcat/src/test/java/app/single/com/oath/micro/server/SingleClassTest.java b/micro-tomcat/src/test/java/app/single/com/oath/micro/server/SingleClassTest.java new file mode 100644 index 000000000..324cf4dce --- /dev/null +++ b/micro-tomcat/src/test/java/app/single/com/oath/micro/server/SingleClassTest.java @@ -0,0 +1,59 @@ +package app.single.com.oath.micro.server; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.auto.discovery.RestResource; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.testing.RestAgent; + +@Microserver +@Path("/single") +public class SingleClassTest implements RestResource{ + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + @Before + public void startServer() throws InterruptedException{ + + server = new MicroserverApp( SingleClassTest.class, ()-> "simple-app"); + Thread.sleep(1000); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + + + assertThat(rest.get("http://localhost:8080/simple-app/single/ping"),is("ok")); + + } + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "ok"; + } + + +} \ No newline at end of file diff --git a/micro-tomcat/src/test/java/app/single/main/com/aol/micro/server/SingleClassApp.java b/micro-tomcat/src/test/java/app/single/main/com/aol/micro/server/SingleClassApp.java deleted file mode 100644 index aef7a170c..000000000 --- a/micro-tomcat/src/test/java/app/single/main/com/aol/micro/server/SingleClassApp.java +++ /dev/null @@ -1,24 +0,0 @@ -package app.single.main.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.Rest; - -@Rest -@Path("/status") -public class SingleClassApp { - - public static void main(String[] args){ - new MicroserverApp(()-> "simple-app").run(); - } - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "ok"; - } - -} diff --git a/micro-tomcat/src/test/java/app/single/main/com/oath/micro/server/SingleClassApp.java b/micro-tomcat/src/test/java/app/single/main/com/oath/micro/server/SingleClassApp.java new file mode 100644 index 000000000..2d7a71917 --- /dev/null +++ b/micro-tomcat/src/test/java/app/single/main/com/oath/micro/server/SingleClassApp.java @@ -0,0 +1,24 @@ +package app.single.main.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.auto.discovery.Rest; + +@Rest +@Path("/status") +public class SingleClassApp { + + public static void main(String[] args){ + new MicroserverApp(()-> "simple-app").run(); + } + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "ok"; + } + +} diff --git a/micro-tomcat/src/test/java/app/single/serverconfig/com/aol/micro/server/SingleClassTest.java b/micro-tomcat/src/test/java/app/single/serverconfig/com/aol/micro/server/SingleClassTest.java deleted file mode 100644 index 5c0cb67b8..000000000 --- a/micro-tomcat/src/test/java/app/single/serverconfig/com/aol/micro/server/SingleClassTest.java +++ /dev/null @@ -1,65 +0,0 @@ -package app.single.serverconfig.com.aol.micro.server; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.*; - -import java.util.concurrent.ExecutionException; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.RestResource; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.module.ConfigurableModule; -import com.aol.micro.server.testing.RestAgent; - - -@Path("/single") -public class SingleClassTest implements RestResource{ - - RestAgent rest = new RestAgent(); - - boolean called; - MicroserverApp server; - @Before - public void startServer() throws InterruptedException{ - called = false; - server = new MicroserverApp( ConfigurableModule.builder() - .context("hello") - .serverConfigManager(server->called=true) - .build()); - Thread.sleep(1000); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - - - assertThat(rest.get("http://localhost:8080/hello/single/ping"),is("ok")); - assertTrue(called); - - } - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return "ok"; - } - - -} \ No newline at end of file diff --git a/micro-tomcat/src/test/java/app/single/serverconfig/com/oath/micro/server/SingleClassTest.java b/micro-tomcat/src/test/java/app/single/serverconfig/com/oath/micro/server/SingleClassTest.java new file mode 100644 index 000000000..6d0bc5d09 --- /dev/null +++ b/micro-tomcat/src/test/java/app/single/serverconfig/com/oath/micro/server/SingleClassTest.java @@ -0,0 +1,64 @@ +package app.single.serverconfig.com.oath.micro.server; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.*; + +import java.util.concurrent.ExecutionException; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.auto.discovery.RestResource; +import com.oath.micro.server.module.ConfigurableModule; +import com.oath.micro.server.testing.RestAgent; + + +@Path("/single") +public class SingleClassTest implements RestResource{ + + RestAgent rest = new RestAgent(); + + boolean called; + MicroserverApp server; + @Before + public void startServer() throws InterruptedException{ + called = false; + server = new MicroserverApp( ConfigurableModule.builder() + .context("hello") + .serverConfigManager(server->called=true) + .build()); + Thread.sleep(1000); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + + + assertThat(rest.get("http://localhost:8080/hello/single/ping"),is("ok")); + assertTrue(called); + + } + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return "ok"; + } + + +} \ No newline at end of file diff --git a/micro-tomcat/src/test/java/app/spring/com/aol/micro/server/MyBean.java b/micro-tomcat/src/test/java/app/spring/com/aol/micro/server/MyBean.java deleted file mode 100644 index 1f7a589ff..000000000 --- a/micro-tomcat/src/test/java/app/spring/com/aol/micro/server/MyBean.java +++ /dev/null @@ -1,12 +0,0 @@ -package app.spring.com.aol.micro.server; - -import javax.inject.Inject; - -import lombok.Getter; - -@Getter -public class MyBean { - - @Inject - private MyDependency injected; -} diff --git a/micro-tomcat/src/test/java/app/spring/com/aol/micro/server/MyDependency.java b/micro-tomcat/src/test/java/app/spring/com/aol/micro/server/MyDependency.java deleted file mode 100644 index 48d89e6c5..000000000 --- a/micro-tomcat/src/test/java/app/spring/com/aol/micro/server/MyDependency.java +++ /dev/null @@ -1,12 +0,0 @@ -package app.spring.com.aol.micro.server; - -import lombok.Getter; - -import org.springframework.stereotype.Component; - -@Component -@Getter -public class MyDependency { - - private String data = "hello world"; -} diff --git a/micro-tomcat/src/test/java/app/spring/com/aol/micro/server/SpringRunnerTest.java b/micro-tomcat/src/test/java/app/spring/com/aol/micro/server/SpringRunnerTest.java deleted file mode 100644 index 6f777ba02..000000000 --- a/micro-tomcat/src/test/java/app/spring/com/aol/micro/server/SpringRunnerTest.java +++ /dev/null @@ -1,55 +0,0 @@ -package app.spring.com.aol.micro.server; - - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.springframework.context.annotation.Bean; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.testing.RestAgent; -/**@Configuration -@ComponentScan(basePackages = { "app.spring.com.aol.micro.server" })**/ -@Microserver -public class SpringRunnerTest { - - RestAgent rest = new RestAgent(); - - @Bean - public MyBean mybean(){ - return new MyBean(); - } - - MicroserverApp server; - @Before - public void startServer() throws InterruptedException{ - - server = new MicroserverApp( SpringRunnerTest.class, ()-> "spring-app"); - Thread.sleep(1000); - server.start(); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void testAutoWiring() throws InterruptedException, ExecutionException{ - - assertThat(rest.get("http://localhost:8080/spring-app/spring/ping"),is("hello world")); - - } - - - - - -} diff --git a/micro-tomcat/src/test/java/app/spring/com/aol/micro/server/SpringStatusResource.java b/micro-tomcat/src/test/java/app/spring/com/aol/micro/server/SpringStatusResource.java deleted file mode 100644 index 331ac997e..000000000 --- a/micro-tomcat/src/test/java/app/spring/com/aol/micro/server/SpringStatusResource.java +++ /dev/null @@ -1,32 +0,0 @@ -package app.spring.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.RestResource; - -@Component -@Path("/spring") -public class SpringStatusResource implements RestResource { - - @Autowired - private MyBean mybean; - - @GET - @Produces("text/plain") - @Path("/ping") - public String ping() { - return mybean.getInjected().getData(); - } - @GET - @Produces("text/plain") - @Path("/ping2") - public String ping2() { - return "ok"; - } - -} \ No newline at end of file diff --git a/micro-tomcat/src/test/java/app/spring/com/oath/micro/server/MyBean.java b/micro-tomcat/src/test/java/app/spring/com/oath/micro/server/MyBean.java new file mode 100644 index 000000000..328b7d185 --- /dev/null +++ b/micro-tomcat/src/test/java/app/spring/com/oath/micro/server/MyBean.java @@ -0,0 +1,12 @@ +package app.spring.com.oath.micro.server; + +import javax.inject.Inject; + +import lombok.Getter; + +@Getter +public class MyBean { + + @Inject + private MyDependency injected; +} diff --git a/micro-tomcat/src/test/java/app/spring/com/oath/micro/server/MyDependency.java b/micro-tomcat/src/test/java/app/spring/com/oath/micro/server/MyDependency.java new file mode 100644 index 000000000..1ca23b15b --- /dev/null +++ b/micro-tomcat/src/test/java/app/spring/com/oath/micro/server/MyDependency.java @@ -0,0 +1,12 @@ +package app.spring.com.oath.micro.server; + +import lombok.Getter; + +import org.springframework.stereotype.Component; + +@Component +@Getter +public class MyDependency { + + private String data = "hello world"; +} diff --git a/micro-tomcat/src/test/java/app/spring/com/oath/micro/server/SpringRunnerTest.java b/micro-tomcat/src/test/java/app/spring/com/oath/micro/server/SpringRunnerTest.java new file mode 100644 index 000000000..8fb684d67 --- /dev/null +++ b/micro-tomcat/src/test/java/app/spring/com/oath/micro/server/SpringRunnerTest.java @@ -0,0 +1,55 @@ +package app.spring.com.oath.micro.server; + + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.springframework.context.annotation.Bean; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.testing.RestAgent; +/**@Configuration +@ComponentScan(basePackages = { "app.spring.com.oath.micro.server" })**/ +@Microserver +public class SpringRunnerTest { + + RestAgent rest = new RestAgent(); + + @Bean + public MyBean mybean(){ + return new MyBean(); + } + + MicroserverApp server; + @Before + public void startServer() throws InterruptedException{ + + server = new MicroserverApp( SpringRunnerTest.class, ()-> "spring-app"); + Thread.sleep(1000); + server.start(); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void testAutoWiring() throws InterruptedException, ExecutionException{ + + assertThat(rest.get("http://localhost:8080/spring-app/spring/ping"),is("hello world")); + + } + + + + + +} diff --git a/micro-tomcat/src/test/java/app/spring/com/oath/micro/server/SpringStatusResource.java b/micro-tomcat/src/test/java/app/spring/com/oath/micro/server/SpringStatusResource.java new file mode 100644 index 000000000..ae0c817de --- /dev/null +++ b/micro-tomcat/src/test/java/app/spring/com/oath/micro/server/SpringStatusResource.java @@ -0,0 +1,32 @@ +package app.spring.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.RestResource; + +@Component +@Path("/spring") +public class SpringStatusResource implements RestResource { + + @Autowired + private MyBean mybean; + + @GET + @Produces("text/plain") + @Path("/ping") + public String ping() { + return mybean.getInjected().getData(); + } + @GET + @Produces("text/plain") + @Path("/ping2") + public String ping2() { + return "ok"; + } + +} \ No newline at end of file diff --git a/micro-tomcat/src/test/java/app/validation/com/aol/micro/server/ImmutableEntity.java b/micro-tomcat/src/test/java/app/validation/com/aol/micro/server/ImmutableEntity.java deleted file mode 100644 index 5b454305d..000000000 --- a/micro-tomcat/src/test/java/app/validation/com/aol/micro/server/ImmutableEntity.java +++ /dev/null @@ -1,28 +0,0 @@ -package app.validation.com.aol.micro.server; - - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Builder; - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "") -@XmlRootElement(name = "immutable") -@Getter -@AllArgsConstructor -@Builder -public class ImmutableEntity { - - private final String value; - - - public ImmutableEntity() { - this(null); - } - -} diff --git a/micro-tomcat/src/test/java/app/validation/com/aol/micro/server/ValidationAppResource.java b/micro-tomcat/src/test/java/app/validation/com/aol/micro/server/ValidationAppResource.java deleted file mode 100644 index 880c619e8..000000000 --- a/micro-tomcat/src/test/java/app/validation/com/aol/micro/server/ValidationAppResource.java +++ /dev/null @@ -1,23 +0,0 @@ -package app.validation.com.aol.micro.server; - -import javax.validation.constraints.NotNull; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.stereotype.Component; - -import com.aol.micro.server.auto.discovery.RestResource; -@Component -@Path("/status") -public class ValidationAppResource implements RestResource { - - @POST - @Produces("application/json") - @Path("/ping") - public ImmutableEntity ping( @NotNull ImmutableEntity entity) { - return entity; - } - - -} diff --git a/micro-tomcat/src/test/java/app/validation/com/aol/micro/server/ValidationAppTest.java b/micro-tomcat/src/test/java/app/validation/com/aol/micro/server/ValidationAppTest.java deleted file mode 100644 index e7bf73536..000000000 --- a/micro-tomcat/src/test/java/app/validation/com/aol/micro/server/ValidationAppTest.java +++ /dev/null @@ -1,75 +0,0 @@ -package app.validation.com.aol.micro.server; - -import java.util.concurrent.ExecutionException; - -import javax.ws.rs.BadRequestException; - -import com.oath.cyclops.types.futurestream.SimpleReactStream; -import cyclops.async.SimpleReact; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.testing.RestAgent; - -//@Microserver(basePackages = { "app.guava.com.aol.micro.server" }) -public class ValidationAppTest { - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - - ImmutableEntity entity; - - - SimpleReact simpleReact = new SimpleReact(); - SimpleReactStream stream; - - @Before - public void startServer() throws InterruptedException { - server = new MicroserverApp(() -> "guava-app"); - Thread.sleep(1000); - server.start(); - - - entity = ImmutableEntity.builder().value("value").build(); - - - } - - @After - public void stopServer() { - server.stop(); - } - - - @Test(expected=BadRequestException.class) - public void confirmError() throws InterruptedException, - ExecutionException { - - - //stream.block(); - - rest.post( - "http://localhost:8080/guava-app/status/ping", null, - ImmutableEntity.class); - - - } - @Test - public void confirmNoError() throws InterruptedException, - ExecutionException { - - //stream.block(); - rest.post( - "http://localhost:8080/guava-app/status/ping", entity, - ImmutableEntity.class); - - - } - - - -} diff --git a/micro-tomcat/src/test/java/app/validation/com/oath/micro/server/ImmutableEntity.java b/micro-tomcat/src/test/java/app/validation/com/oath/micro/server/ImmutableEntity.java new file mode 100644 index 000000000..19e8f5b26 --- /dev/null +++ b/micro-tomcat/src/test/java/app/validation/com/oath/micro/server/ImmutableEntity.java @@ -0,0 +1,28 @@ +package app.validation.com.oath.micro.server; + + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Builder; + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "") +@XmlRootElement(name = "immutable") +@Getter +@AllArgsConstructor +@Builder +public class ImmutableEntity { + + private final String value; + + + public ImmutableEntity() { + this(null); + } + +} diff --git a/micro-tomcat/src/test/java/app/validation/com/oath/micro/server/ValidationAppResource.java b/micro-tomcat/src/test/java/app/validation/com/oath/micro/server/ValidationAppResource.java new file mode 100644 index 000000000..7a8d0c325 --- /dev/null +++ b/micro-tomcat/src/test/java/app/validation/com/oath/micro/server/ValidationAppResource.java @@ -0,0 +1,23 @@ +package app.validation.com.oath.micro.server; + +import javax.validation.constraints.NotNull; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.stereotype.Component; + +import com.oath.micro.server.auto.discovery.RestResource; +@Component +@Path("/status") +public class ValidationAppResource implements RestResource { + + @POST + @Produces("application/json") + @Path("/ping") + public ImmutableEntity ping( @NotNull ImmutableEntity entity) { + return entity; + } + + +} diff --git a/micro-tomcat/src/test/java/app/validation/com/oath/micro/server/ValidationAppTest.java b/micro-tomcat/src/test/java/app/validation/com/oath/micro/server/ValidationAppTest.java new file mode 100644 index 000000000..fcae5d3bf --- /dev/null +++ b/micro-tomcat/src/test/java/app/validation/com/oath/micro/server/ValidationAppTest.java @@ -0,0 +1,75 @@ +package app.validation.com.oath.micro.server; + +import java.util.concurrent.ExecutionException; + +import javax.ws.rs.BadRequestException; + +import com.oath.cyclops.types.futurestream.SimpleReactStream; +import cyclops.async.SimpleReact; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.testing.RestAgent; + +//@Microserver(basePackages = { "app.guava.com.aol.micro.server" }) +public class ValidationAppTest { + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + + ImmutableEntity entity; + + + SimpleReact simpleReact = new SimpleReact(); + SimpleReactStream stream; + + @Before + public void startServer() throws InterruptedException { + server = new MicroserverApp(() -> "guava-app"); + Thread.sleep(1000); + server.start(); + + + entity = ImmutableEntity.builder().value("value").build(); + + + } + + @After + public void stopServer() { + server.stop(); + } + + + @Test(expected=BadRequestException.class) + public void confirmError() throws InterruptedException, + ExecutionException { + + + //stream.block(); + + rest.post( + "http://localhost:8080/guava-app/status/ping", null, + ImmutableEntity.class); + + + } + @Test + public void confirmNoError() throws InterruptedException, + ExecutionException { + + //stream.block(); + rest.post( + "http://localhost:8080/guava-app/status/ping", entity, + ImmutableEntity.class); + + + } + + + +} diff --git a/micro-tomcat/src/test/java/com/aol/micro/server/servers/ServerRunnerTest.java b/micro-tomcat/src/test/java/com/aol/micro/server/servers/ServerRunnerTest.java deleted file mode 100644 index e1f0d7c12..000000000 --- a/micro-tomcat/src/test/java/com/aol/micro/server/servers/ServerRunnerTest.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.aol.micro.server.servers; - -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - -import java.util.Arrays; -import java.util.concurrent.CompletableFuture; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mockito; -import org.springframework.context.ApplicationContext; - -import com.aol.micro.server.servers.model.AllData; -import com.aol.micro.server.servers.model.ServerData; -import com.aol.micro.server.servers.tomcat.TomcatApplication; - - - -public class ServerRunnerTest { - - private ServerRunner serverRunner; - private TomcatApplication serverApplication1; - private TomcatApplication serverApplication2; - private ServerData[] registered; - volatile int server1Count =0; - volatile int server2Count =0; - @Before - public void setUp() { - - server1Count =0; - server2Count =0; - - ServerData data1 = new ServerData(8080,Arrays.asList(), Mockito.mock(ApplicationContext.class), "url1", () -> "app-context"); - ServerData data2 = new ServerData(8081, Arrays.asList(), Mockito.mock(ApplicationContext.class), "url2", () -> "test-context"); - - serverApplication1 = new TomcatApplication(AllData.builder().serverData(data1).build()){ - @Override - public void run(CompletableFuture start,JaxRsServletConfigurer jaxRsConfigurer, CompletableFuture end) { - server1Count++; - start.complete(true); - - } - }; - serverApplication2 = new TomcatApplication(AllData.builder().serverData(data2).build()){ - @Override - public void run(CompletableFuture start,JaxRsServletConfigurer jaxRsConfigurer,CompletableFuture end) { - server2Count++; - start.complete(true); - - } - }; - - serverRunner = new ServerRunner( (array) -> {registered = array; } , - Arrays.asList(serverApplication1, serverApplication2), new CompletableFuture()); - - - } - - @Test - public void testRun() { - serverRunner.run(); - assertThat(server1Count,is(1)); - assertThat(server2Count,is(1)); - } -} diff --git a/micro-tomcat/src/test/java/com/aol/micro/server/testing/RestAgent.java b/micro-tomcat/src/test/java/com/aol/micro/server/testing/RestAgent.java deleted file mode 100644 index 24b169f2e..000000000 --- a/micro-tomcat/src/test/java/com/aol/micro/server/testing/RestAgent.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.aol.micro.server.testing; - -import java.util.List; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.Invocation.Builder; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import com.aol.micro.server.rest.jackson.JacksonUtil; - -public class RestAgent { - - - public String getJson(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.get(String.class); - - } - - public String get(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.TEXT_PLAIN); - - return request.get(String.class); - - } - - public T post(String url, Object payload,Class type) { - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); - } - - public Response postString(String url, String payload) { - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.post(Entity.entity(payload,MediaType.APPLICATION_JSON)); - } - -} diff --git a/micro-tomcat/src/test/java/com/oath/micro/server/servers/ServerRunnerTest.java b/micro-tomcat/src/test/java/com/oath/micro/server/servers/ServerRunnerTest.java new file mode 100644 index 000000000..70f8ec704 --- /dev/null +++ b/micro-tomcat/src/test/java/com/oath/micro/server/servers/ServerRunnerTest.java @@ -0,0 +1,66 @@ +package com.oath.micro.server.servers; + +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + +import java.util.Arrays; +import java.util.concurrent.CompletableFuture; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.springframework.context.ApplicationContext; + +import com.oath.micro.server.servers.model.AllData; +import com.oath.micro.server.servers.model.ServerData; +import com.oath.micro.server.servers.tomcat.TomcatApplication; + + + +public class ServerRunnerTest { + + private ServerRunner serverRunner; + private TomcatApplication serverApplication1; + private TomcatApplication serverApplication2; + private ServerData[] registered; + volatile int server1Count =0; + volatile int server2Count =0; + @Before + public void setUp() { + + server1Count =0; + server2Count =0; + + ServerData data1 = new ServerData(8080,Arrays.asList(), Mockito.mock(ApplicationContext.class), "url1", () -> "app-context"); + ServerData data2 = new ServerData(8081, Arrays.asList(), Mockito.mock(ApplicationContext.class), "url2", () -> "test-context"); + + serverApplication1 = new TomcatApplication(AllData.builder().serverData(data1).build()){ + @Override + public void run(CompletableFuture start,JaxRsServletConfigurer jaxRsConfigurer, CompletableFuture end) { + server1Count++; + start.complete(true); + + } + }; + serverApplication2 = new TomcatApplication(AllData.builder().serverData(data2).build()){ + @Override + public void run(CompletableFuture start,JaxRsServletConfigurer jaxRsConfigurer,CompletableFuture end) { + server2Count++; + start.complete(true); + + } + }; + + serverRunner = new ServerRunner( (array) -> {registered = array; } , + Arrays.asList(serverApplication1, serverApplication2), new CompletableFuture()); + + + } + + @Test + public void testRun() { + serverRunner.run(); + assertThat(server1Count,is(1)); + assertThat(server2Count,is(1)); + } +} diff --git a/micro-tomcat/src/test/java/com/oath/micro/server/testing/RestAgent.java b/micro-tomcat/src/test/java/com/oath/micro/server/testing/RestAgent.java new file mode 100644 index 000000000..7b83464d9 --- /dev/null +++ b/micro-tomcat/src/test/java/com/oath/micro/server/testing/RestAgent.java @@ -0,0 +1,64 @@ +package com.oath.micro.server.testing; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.Invocation.Builder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import com.oath.micro.server.rest.jackson.JacksonUtil; + +public class RestAgent { + + + public String getJson(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.get(String.class); + + } + + public String get(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.TEXT_PLAIN); + + return request.get(String.class); + + } + + public T post(String url, Object payload,Class type) { + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); + } + + public Response postString(String url, String payload) { + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.post(Entity.entity(payload,MediaType.APPLICATION_JSON)); + } + +} diff --git a/micro-transactions/src/main/java/com/aol/micro/server/transactions/TransactionsPlugin.java b/micro-transactions/src/main/java/com/aol/micro/server/transactions/TransactionsPlugin.java deleted file mode 100644 index d7f036fe8..000000000 --- a/micro-transactions/src/main/java/com/aol/micro/server/transactions/TransactionsPlugin.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.aol.micro.server.transactions; - -import com.aol.micro.server.Plugin; -import cyclops.collections.immutable.PersistentSetX; -import cyclops.collections.mutable.SetX; - -import java.util.Set; - -/** - * - * @author johnmcclean - * - */ -public class TransactionsPlugin implements Plugin{ - - @Override - public Set springClasses() { - return SetX.of(TransactionConfiguration.class); - } - - - -} diff --git a/micro-transactions/src/main/java/com/aol/micro/server/transactions/TransactionConfiguration.java b/micro-transactions/src/main/java/com/oath/micro/server/transactions/TransactionConfiguration.java similarity index 94% rename from micro-transactions/src/main/java/com/aol/micro/server/transactions/TransactionConfiguration.java rename to micro-transactions/src/main/java/com/oath/micro/server/transactions/TransactionConfiguration.java index 677e763d1..fb99e908c 100644 --- a/micro-transactions/src/main/java/com/aol/micro/server/transactions/TransactionConfiguration.java +++ b/micro-transactions/src/main/java/com/oath/micro/server/transactions/TransactionConfiguration.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.transactions; +package com.oath.micro.server.transactions; import java.util.function.Function; diff --git a/micro-transactions/src/main/java/com/aol/micro/server/transactions/TransactionFlow.java b/micro-transactions/src/main/java/com/oath/micro/server/transactions/TransactionFlow.java similarity index 98% rename from micro-transactions/src/main/java/com/aol/micro/server/transactions/TransactionFlow.java rename to micro-transactions/src/main/java/com/oath/micro/server/transactions/TransactionFlow.java index 435723fcb..101330669 100644 --- a/micro-transactions/src/main/java/com/aol/micro/server/transactions/TransactionFlow.java +++ b/micro-transactions/src/main/java/com/oath/micro/server/transactions/TransactionFlow.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.transactions; +package com.oath.micro.server.transactions; import java.util.function.Consumer; import java.util.function.Function; diff --git a/micro-transactions/src/main/java/com/oath/micro/server/transactions/TransactionsPlugin.java b/micro-transactions/src/main/java/com/oath/micro/server/transactions/TransactionsPlugin.java new file mode 100644 index 000000000..99ab8776f --- /dev/null +++ b/micro-transactions/src/main/java/com/oath/micro/server/transactions/TransactionsPlugin.java @@ -0,0 +1,22 @@ +package com.oath.micro.server.transactions; + +import com.oath.micro.server.Plugin; +import cyclops.collections.mutable.SetX; + +import java.util.Set; + +/** + * + * @author johnmcclean + * + */ +public class TransactionsPlugin implements Plugin{ + + @Override + public Set springClasses() { + return SetX.of(TransactionConfiguration.class); + } + + + +} diff --git a/micro-transactions/src/main/resources/META-INF/services/com.aol.micro.server.Plugin b/micro-transactions/src/main/resources/META-INF/services/com.aol.micro.server.Plugin deleted file mode 100644 index 6394d103e..000000000 --- a/micro-transactions/src/main/resources/META-INF/services/com.aol.micro.server.Plugin +++ /dev/null @@ -1 +0,0 @@ -com.aol.micro.server.transactions.TransactionsPlugin \ No newline at end of file diff --git a/micro-transactions/src/main/resources/META-INF/services/com.oath.micro.server.Plugin b/micro-transactions/src/main/resources/META-INF/services/com.oath.micro.server.Plugin new file mode 100644 index 000000000..14d71235a --- /dev/null +++ b/micro-transactions/src/main/resources/META-INF/services/com.oath.micro.server.Plugin @@ -0,0 +1 @@ +com.oath.micro.server.transactions.TransactionsPlugin \ No newline at end of file diff --git a/micro-transactions/src/test/java/app/jdbc/transaction/com/aol/micro/server/JdbcEntity.java b/micro-transactions/src/test/java/app/jdbc/transaction/com/aol/micro/server/JdbcEntity.java deleted file mode 100644 index 1fc6c9f38..000000000 --- a/micro-transactions/src/test/java/app/jdbc/transaction/com/aol/micro/server/JdbcEntity.java +++ /dev/null @@ -1,27 +0,0 @@ -package app.jdbc.transaction.com.aol.micro.server; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.Builder; - - - - -@Setter -@Getter -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class JdbcEntity implements java.io.Serializable { - - private static final long serialVersionUID = 1L; - - private Long id; - private String name; - private String value; - private int version; - - -} diff --git a/micro-transactions/src/test/java/app/jdbc/transaction/com/aol/micro/server/JdbcRunnerTest.java b/micro-transactions/src/test/java/app/jdbc/transaction/com/aol/micro/server/JdbcRunnerTest.java deleted file mode 100644 index 364e0efd3..000000000 --- a/micro-transactions/src/test/java/app/jdbc/transaction/com/aol/micro/server/JdbcRunnerTest.java +++ /dev/null @@ -1,60 +0,0 @@ -package app.jdbc.transaction.com.aol.micro.server; - - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.ExecutionException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import app.jdbc.transaction.com.aol.micro.server.JdbcEntity; - -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; -import com.aol.micro.server.rest.client.nio.AsyncRestClient; -import com.aol.micro.server.testing.RestAgent; - -@Microserver(properties={"db.connection.driver","org.hsqldb.jdbcDriver", - "db.connection.url","jdbc:hsqldb:mem:aname", - "db.connection.username", "sa", - }) -public class JdbcRunnerTest { - - private final AsyncRestClient listClient = new AsyncRestClient(1000,1000).withResponse(JdbcEntity.class); - - RestAgent rest = new RestAgent(); - - MicroserverApp server; - - @Before - public void startServer(){ - - - server = new MicroserverApp(()->"jdbc-app"); - server.start(); - rest.get("http://localhost:8080/jdbc-app/persistence/gen"); - - } - - @After - public void stopServer(){ - server.stop(); - } - - @Test - public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ - - - - assertThat(rest.get("http://localhost:8080/jdbc-app/persistence/create"),is("ok")); - assertThat(listClient.get("http://localhost:8080/jdbc-app/persistence/get").get(),is(JdbcEntity.class)); - - - } - - - -} diff --git a/micro-transactions/src/test/java/app/jdbc/transaction/com/aol/micro/server/PersistentResource.java b/micro-transactions/src/test/java/app/jdbc/transaction/com/aol/micro/server/PersistentResource.java deleted file mode 100644 index 1f6b9807d..000000000 --- a/micro-transactions/src/test/java/app/jdbc/transaction/com/aol/micro/server/PersistentResource.java +++ /dev/null @@ -1,56 +0,0 @@ -package app.jdbc.transaction.com.aol.micro.server; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.BeanPropertyRowMapper; - -import app.jdbc.transaction.com.aol.micro.server.JdbcEntity; - -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.spring.datasource.jdbc.SQL; -import com.aol.micro.server.transactions.TransactionFlow; - -@Rest -@Path("/persistence") -public class PersistentResource { - - private final SQL dao; - private final TransactionFlow flow; - - @Autowired - public PersistentResource(TransactionFlow flow,SQL dao) { - - this.dao = dao; - this.flow=flow; - } - @GET - @Produces("text/plain") - @Path("/gen") - public String gen() { - dao.getJdbc().execute("create table t_jdbc(id bigint,name varchar(255),value varchar(255),version int);"); - - return "ok"; - } - @GET - @Produces("text/plain") - @Path("/create") - public String createEntity() { - - flow.map(name->dao.getJdbc().update("insert into t_jdbc VALUES (1,'"+name+"+','world',1)")) - .execute("hello"); - - - return "ok"; - } - - @GET - @Produces("application/json") - @Path("/get") - public JdbcEntity get() { - return dao.getJdbc(). queryForObject("select * from t_jdbc", new BeanPropertyRowMapper(JdbcEntity.class)); - } - -} \ No newline at end of file diff --git a/micro-transactions/src/test/java/app/jdbc/transaction/com/oath/micro/server/JdbcEntity.java b/micro-transactions/src/test/java/app/jdbc/transaction/com/oath/micro/server/JdbcEntity.java new file mode 100644 index 000000000..6760e7a2b --- /dev/null +++ b/micro-transactions/src/test/java/app/jdbc/transaction/com/oath/micro/server/JdbcEntity.java @@ -0,0 +1,27 @@ +package app.jdbc.transaction.com.oath.micro.server; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.Builder; + + + + +@Setter +@Getter +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class JdbcEntity implements java.io.Serializable { + + private static final long serialVersionUID = 1L; + + private Long id; + private String name; + private String value; + private int version; + + +} diff --git a/micro-transactions/src/test/java/app/jdbc/transaction/com/oath/micro/server/JdbcRunnerTest.java b/micro-transactions/src/test/java/app/jdbc/transaction/com/oath/micro/server/JdbcRunnerTest.java new file mode 100644 index 000000000..9be773144 --- /dev/null +++ b/micro-transactions/src/test/java/app/jdbc/transaction/com/oath/micro/server/JdbcRunnerTest.java @@ -0,0 +1,58 @@ +package app.jdbc.transaction.com.oath.micro.server; + + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutionException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; +import com.oath.micro.server.rest.client.nio.AsyncRestClient; +import com.oath.micro.server.testing.RestAgent; + +@Microserver(properties={"db.connection.driver","org.hsqldb.jdbcDriver", + "db.connection.url","jdbc:hsqldb:mem:aname", + "db.connection.username", "sa", + }) +public class JdbcRunnerTest { + + private final AsyncRestClient listClient = new AsyncRestClient(1000,1000).withResponse(JdbcEntity.class); + + RestAgent rest = new RestAgent(); + + MicroserverApp server; + + @Before + public void startServer(){ + + + server = new MicroserverApp(()->"jdbc-app"); + server.start(); + rest.get("http://localhost:8080/jdbc-app/persistence/gen"); + + } + + @After + public void stopServer(){ + server.stop(); + } + + @Test + public void runAppAndBasicTest() throws InterruptedException, ExecutionException{ + + + + assertThat(rest.get("http://localhost:8080/jdbc-app/persistence/create"),is("ok")); + assertThat(listClient.get("http://localhost:8080/jdbc-app/persistence/get").get(),is(JdbcEntity.class)); + + + } + + + +} diff --git a/micro-transactions/src/test/java/app/jdbc/transaction/com/oath/micro/server/PersistentResource.java b/micro-transactions/src/test/java/app/jdbc/transaction/com/oath/micro/server/PersistentResource.java new file mode 100644 index 000000000..41ac2cbad --- /dev/null +++ b/micro-transactions/src/test/java/app/jdbc/transaction/com/oath/micro/server/PersistentResource.java @@ -0,0 +1,54 @@ +package app.jdbc.transaction.com.oath.micro.server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.BeanPropertyRowMapper; + +import com.oath.micro.server.auto.discovery.Rest; +import com.oath.micro.server.spring.datasource.jdbc.SQL; +import com.oath.micro.server.transactions.TransactionFlow; + +@Rest +@Path("/persistence") +public class PersistentResource { + + private final SQL dao; + private final TransactionFlow flow; + + @Autowired + public PersistentResource(TransactionFlow flow,SQL dao) { + + this.dao = dao; + this.flow=flow; + } + @GET + @Produces("text/plain") + @Path("/gen") + public String gen() { + dao.getJdbc().execute("create table t_jdbc(id bigint,name varchar(255),value varchar(255),version int);"); + + return "ok"; + } + @GET + @Produces("text/plain") + @Path("/create") + public String createEntity() { + + flow.map(name->dao.getJdbc().update("insert into t_jdbc VALUES (1,'"+name+"+','world',1)")) + .execute("hello"); + + + return "ok"; + } + + @GET + @Produces("application/json") + @Path("/get") + public JdbcEntity get() { + return dao.getJdbc(). queryForObject("select * from t_jdbc", new BeanPropertyRowMapper(JdbcEntity.class)); + } + +} \ No newline at end of file diff --git a/micro-transactions/src/test/java/com/aol/micro/server/testing/RestAgent.java b/micro-transactions/src/test/java/com/aol/micro/server/testing/RestAgent.java deleted file mode 100644 index ce204f810..000000000 --- a/micro-transactions/src/test/java/com/aol/micro/server/testing/RestAgent.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.aol.micro.server.testing; - -import java.util.List; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.Invocation.Builder; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; - -import com.aol.micro.server.rest.jackson.JacksonUtil; - -public class RestAgent { - - - public String getJson(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.get(String.class); - - } - - public String get(String url) { - - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.TEXT_PLAIN); - - return request.get(String.class); - - } - - public T post(String url, Object payload,Class type) { - Client client = ClientBuilder.newClient(); - - WebTarget resource = client.target(url); - - Builder request = resource.request(); - request.accept(MediaType.APPLICATION_JSON); - - return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); - } - - -} diff --git a/micro-transactions/src/test/java/com/oath/micro/server/testing/RestAgent.java b/micro-transactions/src/test/java/com/oath/micro/server/testing/RestAgent.java new file mode 100644 index 000000000..b2b86303e --- /dev/null +++ b/micro-transactions/src/test/java/com/oath/micro/server/testing/RestAgent.java @@ -0,0 +1,53 @@ +package com.oath.micro.server.testing; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.Invocation.Builder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; + +import com.oath.micro.server.rest.jackson.JacksonUtil; + +public class RestAgent { + + + public String getJson(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.get(String.class); + + } + + public String get(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.TEXT_PLAIN); + + return request.get(String.class); + + } + + public T post(String url, Object payload,Class type) { + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); + } + + +} diff --git a/micro-transactions/src/test/java/com/aol/micro/server/transactions/TransactionFlowTest.java b/micro-transactions/src/test/java/com/oath/micro/server/transactions/TransactionFlowTest.java similarity index 98% rename from micro-transactions/src/test/java/com/aol/micro/server/transactions/TransactionFlowTest.java rename to micro-transactions/src/test/java/com/oath/micro/server/transactions/TransactionFlowTest.java index 62a8031f5..c7b364b23 100644 --- a/micro-transactions/src/test/java/com/aol/micro/server/transactions/TransactionFlowTest.java +++ b/micro-transactions/src/test/java/com/oath/micro/server/transactions/TransactionFlowTest.java @@ -1,4 +1,4 @@ -package com.aol.micro.server.transactions; +package com.oath.micro.server.transactions; import org.junit.Test; import org.springframework.transaction.TransactionException; diff --git a/micro-tutorial/src/main/java/app1/simple/Job.java b/micro-tutorial/src/main/java/app1/simple/Job.java index 9f4c0b05f..5fc7efbc3 100644 --- a/micro-tutorial/src/main/java/app1/simple/Job.java +++ b/micro-tutorial/src/main/java/app1/simple/Job.java @@ -1,12 +1,11 @@ package app1.simple; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; -import com.aol.micro.server.events.ScheduledJob; -import com.aol.micro.server.events.SystemData; -import com.aol.micro.server.utility.HashMapBuilder; +import com.oath.micro.server.events.ScheduledJob; +import com.oath.micro.server.events.SystemData; +import com.oath.micro.server.utility.HashMapBuilder; @Component public class Job implements ScheduledJob{ diff --git a/micro-tutorial/src/main/java/app1/simple/MicroserverTutorial.java b/micro-tutorial/src/main/java/app1/simple/MicroserverTutorial.java index 6561a552b..31aa3ed7d 100644 --- a/micro-tutorial/src/main/java/app1/simple/MicroserverTutorial.java +++ b/micro-tutorial/src/main/java/app1/simple/MicroserverTutorial.java @@ -1,7 +1,7 @@ package app1.simple; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.config.Microserver; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.config.Microserver; @Microserver(entityScan = "app1.simple", propertiesName="tutorial.properties") public class MicroserverTutorial { diff --git a/micro-tutorial/src/main/java/app1/simple/MyRestEndPoint.java b/micro-tutorial/src/main/java/app1/simple/MyRestEndPoint.java index 77b45ef60..788540b55 100644 --- a/micro-tutorial/src/main/java/app1/simple/MyRestEndPoint.java +++ b/micro-tutorial/src/main/java/app1/simple/MyRestEndPoint.java @@ -16,11 +16,11 @@ import org.springframework.jdbc.core.BeanPropertyRowMapper; -import com.aol.micro.server.auto.discovery.Rest; -import com.aol.micro.server.events.RequestEvents; -import com.aol.micro.server.ip.tracker.QueryIPRetriever; -import com.aol.micro.server.rest.jackson.JacksonUtil; -import com.aol.micro.server.spring.datasource.jdbc.SQL; +import com.oath.micro.server.auto.discovery.Rest; +import com.oath.micro.server.events.RequestEvents; +import com.oath.micro.server.ip.tracker.QueryIPRetriever; +import com.oath.micro.server.rest.jackson.JacksonUtil; +import com.oath.micro.server.spring.datasource.jdbc.SQL; import com.google.common.collect.ImmutableList; import com.google.common.eventbus.EventBus; import com.wordnik.swagger.annotations.Api; diff --git a/micro-tutorial/src/test/java/app1/simple/SimpleAppTest.java b/micro-tutorial/src/test/java/app1/simple/SimpleAppTest.java index d46030b07..5db67e1ba 100644 --- a/micro-tutorial/src/test/java/app1/simple/SimpleAppTest.java +++ b/micro-tutorial/src/test/java/app1/simple/SimpleAppTest.java @@ -8,8 +8,8 @@ import org.junit.Ignore; import org.junit.Test; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.rest.client.nio.AsyncRestClient; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.rest.client.nio.AsyncRestClient; public class SimpleAppTest { diff --git a/micro-tutorial/src/test/java/app1/simple/SingleClassApp.java b/micro-tutorial/src/test/java/app1/simple/SingleClassApp.java index 2bef2be6f..4825dba97 100644 --- a/micro-tutorial/src/test/java/app1/simple/SingleClassApp.java +++ b/micro-tutorial/src/test/java/app1/simple/SingleClassApp.java @@ -4,8 +4,8 @@ import javax.ws.rs.Path; import javax.ws.rs.Produces; -import com.aol.micro.server.MicroserverApp; -import com.aol.micro.server.auto.discovery.Rest; +import com.oath.micro.server.MicroserverApp; +import com.oath.micro.server.auto.discovery.Rest; @Rest @Path("/status")