Java Code Examples for org.apache.tomcat.util.descriptor.web.ContextEnvironment#setDescription()

The following examples show how to use org.apache.tomcat.util.descriptor.web.ContextEnvironment#setDescription() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HeartbeatTest.java    From TeaStore with Apache License 2.0 5 votes vote down vote up
private Tomcat createClientTomcat(Service service, Tomcat tomcat) throws ServletException, LifecycleException {
		int clientPort = getNextClientPort();
		tomcat.getEngine().setName("Catalina" + clientPort);
		tomcat.setPort(clientPort);
		tomcat.setBaseDir(testWorkingDir);
		tomcat.enableNaming();
		Context context = tomcat.addWebapp("/" + service.getServiceName(), testWorkingDir);
		ContextEnvironment registryURL = new ContextEnvironment();
		registryURL.setDescription("");
		registryURL.setOverride(false);
		registryURL.setType("java.lang.String");
		registryURL.setName("registryURL");
		registryURL.setValue("http://localhost:" + getRegistryPort() + "/test/rest/services/");
		context.getNamingResources().addEnvironment(registryURL);
		ContextEnvironment servicePort = new ContextEnvironment();
		servicePort.setDescription("");
		servicePort.setOverride(false);
		servicePort.setType("java.lang.String");
	    servicePort.setName("servicePort");
	    servicePort.setValue("" + clientPort);
		context.getNamingResources().addEnvironment(servicePort);		
		context.addApplicationListener(TestRegistryClientStartup.class.getName());
//		HeartbeatServlet heartbeatServlet = new HeartbeatServlet();
//		tomcat.addServlet("/" + service.getServiceName(), "heartbeatServlet", heartbeatServlet);
//		context.addServletMappingDecoded("/heartbeat", "heartbeatServlet");
		tomcat.start();
		return tomcat;
	}
 
Example 2
Source File: AbstractUiTest.java    From TeaStore with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() throws ServletException, LifecycleException, InterruptedException, JsonProcessingException {
	webUITomcat = new Tomcat();
	webUITomcat.setPort(3000);
	webUITomcat.setBaseDir(testWorkingDir);
	webUITomcat.enableNaming();
	Context context = webUITomcat.addWebapp(CONTEXT, System.getProperty("user.dir") + File.separator + "src"
			+ File.separator + "main" + File.separator + "webapp");
	ContextEnvironment registryURL = new ContextEnvironment();
	registryURL.setDescription("");
	registryURL.setOverride(false);
	registryURL.setType("java.lang.String");
	registryURL.setName("registryURL");
	registryURL.setValue("http://localhost:9001/tools.descartes.teastore.registry/rest/services/");
	context.getNamingResources().addEnvironment(registryURL);
	webUITomcat.addServlet(CONTEXT, "servlet", getServlet());
	webUITomcat.addServlet(CONTEXT, "index", new IndexServlet());
	webUITomcat.addServlet(CONTEXT, "login", new LoginServlet());
	webUITomcat.addServlet(CONTEXT, "order", new OrderServlet());
	context.addServletMappingDecoded("/test", "servlet");
	context.addServletMappingDecoded("/index", "index");
	context.addServletMappingDecoded("/login", "login");
	context.addServletMappingDecoded("/order", "order");
	context.addWelcomeFile("/index");
	webUITomcat.start();

	// Mock registry
	List<String> strings = new LinkedList<String>();
	strings.add("localhost:9001");
	String json = new ObjectMapper().writeValueAsString(strings);
	wireMockRule.stubFor(get(urlEqualTo(
			"/tools.descartes.teastore.registry/rest/services/" + Service.IMAGE.getServiceName() + "/"))
					.willReturn(okJson(json)));
	wireMockRule.stubFor(get(urlEqualTo(
			"/tools.descartes.teastore.registry/rest/services/" + Service.AUTH.getServiceName() + "/"))
					.willReturn(okJson(json)));
	wireMockRule.stubFor(get(urlEqualTo(
			"/tools.descartes.teastore.registry/rest/services/" + Service.PERSISTENCE.getServiceName() + "/"))
					.willReturn(okJson(json)));
	wireMockRule.stubFor(get(urlEqualTo(
			"/tools.descartes.teastore.registry/rest/services/" + Service.RECOMMENDER.getServiceName() + "/"))
					.willReturn(okJson(json)));

	// Mock images
	HashMap<String, String> img = new HashMap<>();
	img.put("andreBauer", "andreBauer");
	img.put("johannesGrohmann", "johannesGrohmann");
	img.put("joakimKistowski", "joakimKistowski");
	img.put("simonEismann", "simonEismann");
	img.put("norbertSchmitt", "norbertSchmitt");
	img.put("descartesLogo", "descartesLogo");
	img.put("icon", "icon");
	mockValidPostRestCall(img, "/tools.descartes.teastore.image/rest/image/getWebImages");
}
 
Example 3
Source File: AbstractRecommenderRestTest.java    From TeaStore with Apache License 2.0 4 votes vote down vote up
/**
 * Sets up a registry, a persistance unit and a store.
 * 
 * @throws Throwable
 *             Throws uncaught throwables for test to fail.
 */
@Before
public void setup() throws Throwable {
	persistence = new MockPersistenceProvider(persistenceWireMockRule);

	otherrecommender = new MockOtherRecommenderProvider(otherRecommenderWireMockRule);

	setRegistry(new MockRegistry(registryWireMockRule, Arrays.asList(getPersistence().getPort()),
			Arrays.asList(RECOMMENDER_TEST_PORT, otherrecommender.getPort())));

	// debuggging response
	// Response response1 = ClientBuilder
	// .newBuilder().build().target("http://localhost:" + otherrecommender.getPort()
	// + "/"
	// + Service.RECOMMENDER.getServiceName() + "/rest/train/timestamp")
	// .request(MediaType.APPLICATION_JSON).get();
	// System.out.println(response1.getStatus() + ":" +
	// response1.readEntity(String.class));

	// debuggging response
	// Response response0 = ClientBuilder.newBuilder().build()
	// .target("http://localhost:" + MockRegistry.DEFAULT_MOCK_REGISTRY_PORT
	// + "/tools.descartes.teastore.registry/rest/services/"
	// + Service.PERSISTENCE.getServiceName() + "/")
	// .request(MediaType.APPLICATION_JSON).get();
	// System.out.println(response0.getStatus() + ":" +
	// response0.readEntity(String.class));
	//
	// Response response1 = ClientBuilder.newBuilder().build()
	// .target("http://localhost:" + persistence.getPort()
	// + "/tools.descartes.teastore.persistence/rest/orderitems")
	// .request(MediaType.APPLICATION_JSON).get();
	// System.out.println(response1.getStatus() + ":" +
	// response1.readEntity(String.class));

	// Setup recommend tomcat
	testTomcat = new Tomcat();
	testTomcat.setPort(RECOMMENDER_TEST_PORT);
	testTomcat.setBaseDir(testWorkingDir);
	testTomcat.enableNaming();
	Context context = testTomcat.addWebapp("/" + Service.RECOMMENDER.getServiceName(), testWorkingDir);
	ContextEnvironment registryURL3 = new ContextEnvironment();
	registryURL3.setDescription("");
	registryURL3.setOverride(false);
	registryURL3.setType("java.lang.String");
	registryURL3.setName("registryURL");
	registryURL3.setValue(
			"http://localhost:" + registry.getPort() + "/tools.descartes.teastore.registry/rest/services/");
	context.getNamingResources().addEnvironment(registryURL3);
	ContextEnvironment servicePort3 = new ContextEnvironment();
	servicePort3.setDescription("");
	servicePort3.setOverride(false);
	servicePort3.setType("java.lang.String");
	servicePort3.setName("servicePort");
	servicePort3.setValue("" + RECOMMENDER_TEST_PORT);
	context.getNamingResources().addEnvironment(servicePort3);
	ResourceConfig restServletConfig3 = new ResourceConfig();
	restServletConfig3.register(TrainEndpoint.class);
	restServletConfig3.register(RecommendEndpoint.class);
	restServletConfig3.register(RecommendSingleEndpoint.class);
	ServletContainer restServlet3 = new ServletContainer(restServletConfig3);
	testTomcat.addServlet("/" + Service.RECOMMENDER.getServiceName(), "restServlet", restServlet3);
	context.addServletMappingDecoded("/rest/*", "restServlet");
	context.addApplicationListener(RecommenderStartup.class.getName());

	ContextEnvironment recommender = new ContextEnvironment();
	recommender.setDescription("");
	recommender.setOverride(false);
	recommender.setType("java.lang.String");
	recommender.setName("recommenderAlgorithm");
	recommender.setValue("PreprocessedSlopeOne");
	context.getNamingResources().addEnvironment(recommender);

	ContextEnvironment retrainlooptime = new ContextEnvironment();
	retrainlooptime.setDescription("");
	retrainlooptime.setOverride(false);
	retrainlooptime.setType("java.lang.Long");
	retrainlooptime.setName("recommenderLoopTime");
	retrainlooptime.setValue("100");
	context.getNamingResources().addEnvironment(retrainlooptime);

	testTomcat.start();

	try {
		Thread.sleep(5000);
	} catch (InterruptedException e) {
	}
}
 
Example 4
Source File: TomcatTestHandler.java    From TeaStore with Apache License 2.0 4 votes vote down vote up
/**
 * Create a Tomcat test handler for persistence testing.
 * @param count Number of testing tomcats.
 * @param startPort Port to start with (do not use 0 for auto-assigning).
 * @param wireMockRule Wire mock rule for mocking the registry.The test handler will
 * add all services with respective stubs to the rule.
 * @param endpoints Class objects for the endpoints.
 * @throws ServletException Exception on failure.
 * @throws LifecycleException Exception on failure.
 * @throws JsonProcessingException Exception on failure.
 */
public TomcatTestHandler(int count, int startPort, WireMockRule wireMockRule, Class<?>... endpoints)
		throws ServletException, LifecycleException, JsonProcessingException {
	tomcats = new Tomcat[count];
	EMFManagerInitializer.initializeEMF();
	for (int i = 0; i < count; i++) {
		tomcats[i] = new Tomcat();
		tomcats[i].setPort(startPort + i);
		tomcats[i].setBaseDir(testWorkingDir);
		Context context = tomcats[i].addWebapp(CONTEXT, testWorkingDir);
		//Registry
		if (wireMockRule != null) {
			ContextEnvironment registryURL = new ContextEnvironment();
			registryURL.setDescription("");
			registryURL.setOverride(false);
			registryURL.setType("java.lang.String");
			registryURL.setName("registryURL");
			registryURL.setValue("http://localhost:" + wireMockRule.port()
			+ "/tools.descartes.teastore.registry/rest/services/");
			context.getNamingResources().addEnvironment(registryURL);
			ContextEnvironment servicePort = new ContextEnvironment();
			servicePort.setDescription("");
			servicePort.setOverride(false);
			servicePort.setType("java.lang.String");
		    servicePort.setName("servicePort");
		    servicePort.setValue("" + startPort + i);
			context.getNamingResources().addEnvironment(servicePort);
			context.addApplicationListener(RegistrationDaemon.class.getName());
		}
		//REST endpoints
		ResourceConfig restServletConfig = new ResourceConfig();
		for (Class<?> endpoint: endpoints) {
			restServletConfig.register(endpoint);
		}
		ServletContainer restServlet = new ServletContainer(restServletConfig);
		tomcats[i].addServlet(CONTEXT, "restServlet", restServlet);
		context.addServletMappingDecoded("/rest/*", "restServlet");
		tomcats[i].start();
	}
	if (wireMockRule != null) {
		initializeMockRegistry(wireMockRule, count, startPort);
	}
	System.out.println("Initializing Database with size " + CategoryRepository.REPOSITORY.getAllEntities().size());
}
 
Example 5
Source File: AbstractStoreRestTest.java    From TeaStore with Apache License 2.0 4 votes vote down vote up
/**
 * Sets up a store.
 * 
 * @throws Throwable
 *           Throws uncaught throwables for test to fail.
 */
@Before
public void setup() throws Throwable {
  BasicConfigurator.configure();

  storeTomcat = new Tomcat();
  storeTomcat.setPort(3000);
  storeTomcat.setBaseDir(testWorkingDir);
  storeTomcat.enableNaming();
  ContextEnvironment registryUrl3 = new ContextEnvironment();
  registryUrl3.setDescription("");
  registryUrl3.setOverride(false);
  registryUrl3.setType("java.lang.String");
  registryUrl3.setName("registryURL");
  registryUrl3
      .setValue("http://localhost:18080/tools.descartes.teastore.registry/rest/services/");
  Context context3 = storeTomcat.addWebapp("/tools.descartes.teastore.auth", testWorkingDir);
  context3.getNamingResources().addEnvironment(registryUrl3);
  ContextEnvironment servicePort3 = new ContextEnvironment();
  servicePort3.setDescription("");
  servicePort3.setOverride(false);
  servicePort3.setType("java.lang.String");
  servicePort3.setName("servicePort");
  servicePort3.setValue("3000");
  context3.getNamingResources().addEnvironment(servicePort3);
  ResourceConfig restServletConfig3 = new ResourceConfig();
  restServletConfig3.register(AuthCartRest.class);
  restServletConfig3.register(AuthUserActionsRest.class);
  ServletContainer restServlet3 = new ServletContainer(restServletConfig3);
  storeTomcat.addServlet("/tools.descartes.teastore.auth", "restServlet", restServlet3);
  context3.addServletMappingDecoded("/rest/*", "restServlet");
  context3.addApplicationListener(EmptyAuthStartup.class.getName());

  // Mock registry
  List<String> strings = new LinkedList<String>();
  strings.add("localhost:18080");
  String json = new ObjectMapper().writeValueAsString(strings);
  List<String> strings2 = new LinkedList<String>();
  strings2.add("localhost:3000");
  String json2 = new ObjectMapper().writeValueAsString(strings2);
  wireMockRule.stubFor(get(urlEqualTo(
      "/tools.descartes.teastore.registry/rest/services/" + Service.IMAGE.getServiceName() + "/"))
          .willReturn(okJson(json)));
  wireMockRule.stubFor(get(urlEqualTo(
      "/tools.descartes.teastore.registry/rest/services/" + Service.AUTH.getServiceName() + "/"))
          .willReturn(okJson(json2)));
  wireMockRule.stubFor(
      WireMock.put(WireMock.urlMatching("/tools.descartes.teastore.registry/rest/services/"
          + Service.AUTH.getServiceName() + "/.*")).willReturn(okJson(json2)));
  wireMockRule.stubFor(
      WireMock.delete(WireMock.urlMatching("/tools.descartes.teastore.registry/rest/services/"
          + Service.AUTH.getServiceName() + "/.*")).willReturn(okJson(json2)));
  wireMockRule.stubFor(get(urlEqualTo("/tools.descartes.teastore.registry/rest/services/"
      + Service.PERSISTENCE.getServiceName() + "/")).willReturn(okJson(json)));
  wireMockRule.stubFor(get(urlEqualTo("/tools.descartes.teastore.registry/rest/services/"
      + Service.RECOMMENDER.getServiceName() + "/")).willReturn(okJson(json)));

  // Mock images
  HashMap<String, String> img = new HashMap<>();
  img.put("andreBauer", "andreBauer");
  img.put("johannesGrohmann", "johannesGrohmann");
  img.put("joakimKistowski", "joakimKistowski");
  img.put("simonEismann", "simonEismann");
  img.put("norbertSchmitt", "norbertSchmitt");
  img.put("descartesLogo", "descartesLogo");
  img.put("icon", "icon");
  mockValidPostRestCall(img, "/tools.descartes.teastore.image/rest/image/getWebImages");

  storeTomcat.start();
}