@Before public void startJetty() throws Exception { servletTester = new ServletTester(); servletTester.getContext().addEventListener(new GuiceServletContextListener() { final Injector injector = Guice.createInjector(new TestModule()); @Override protected Injector getInjector() { return injector; } }); url = servletTester.createConnector(true) + TestModule.MOUNT_POINT; servletTester.addFilter(GuiceFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST)); servletTester.addServlet(DummyServlet.class, "/*"); servletTester.start(); client = ClientBuilder.newClient(); }
/** * Set the Configuration property via REST interface and check whether the JMX interface returns the same value * * @throws Exception */ //TODO: Use the web target JAXRS API to execute these request possibly ? @Ignore @Test public void testSetRESTGetMBeanLocal() throws Exception { LOGGER.debug("testSetRESTGetMBeanLocal"); ObjectName name = new ObjectName(MMX_MBEAN_OBJECT_NAME); ServletTester tester = new ServletTester(); tester.addServlet(LaxConfigServlet.class, "/config"); tester.start(); for (Triple<String, String, String> triple : mbeanAttributes) { String attrName = triple.getLeft(); String attrType = triple.getRight(); String attrValueStr; if (attrType.equals("int")) attrValueStr = Integer.toString(RandomUtils.nextInt(30000, 65535)); else if (attrType.equals("long")) attrValueStr = Long.toString(RandomUtils.nextLong(10, 1000)); else attrValueStr = RandomStringUtils.randomAlphabetic(10); String str = constructGson(triple.getMiddle(), attrValueStr); HttpTester request = new HttpTester(); request.setMethod("POST"); request.setHeader("Host", "tester"); request.setContent(str); request.setHeader("Content-Type", "application/json"); request.setURI("/config"); HttpTester response = new HttpTester(); //response = response.parse(tester.getResponses(request.generate())); response.parse(tester.getResponses(request.generate())); assertEquals("Values do not match", server.getAttribute(name, triple.getLeft()).toString(), attrValueStr); } }
@BeforeClass public static void startServer() throws Exception { tester = new ServletTester(); ServletContextHandler ctx = tester.getContext(); // set up ServletContext ctx.setContextPath("/"); ctx.setResourceBase("src/main/webapp"); ctx.setClassLoader(ServletTester.class.getClassLoader()); // add digilib ContextListener DigilibServlet3Configuration dlConfig = new DigilibServlet3Configuration(); ctx.addEventListener(dlConfig); tester.addServlet(Scaler.class, "/Scaler/*"); // start the servlet tester.start(); }
/** * Set the Configuration property via JMX and check whether the REST interface returns the same value * * @throws Exception */ //TODO: Use the web target JAXRS API to execute these request possibly ? @Ignore @Test public void testSetMBeanLocalGetREST() throws Exception { ObjectName name = new ObjectName(MMX_MBEAN_OBJECT_NAME); ServletTester tester = new ServletTester(); tester.addServlet(LaxConfigServlet.class, "/config"); tester.start(); for (Triple<String, String, String> triple : mbeanAttributes) { String attrName = triple.getLeft(); String attrType = triple.getRight(); Object attrValue; if (attrType.equals("int")) { attrValue = RandomUtils.nextInt(30000, 65535); } else if(attrType.equals("long")) { attrValue = RandomUtils.nextLong(10, 1000); } else { attrValue = RandomStringUtils.randomAlphabetic(10); } Attribute attr1 = new Attribute(attrName, attrValue); server.setAttribute(name, attr1); Object attr2 = server.getAttribute(name, attrName); assertEquals("Attribute values do not match", attrValue, attr2); HttpTester request = new HttpTester(); // HttpTester.Request request = HttpTester.newRequest(); request.setMethod("GET"); request.setHeader("Host", "tester"); request.setURI("/config"); request.setContent(""); HttpTester response = new HttpTester(); response.parse(tester.getResponses(request.generate())); JsonElement jelement = new JsonParser().parse(response.getContent()); JsonObject jobject = jelement.getAsJsonObject(); jobject = jobject.getAsJsonObject("configs"); String attrValueRest = jobject.get(triple.getMiddle()).getAsString(); if (attrType.equals("int")) assertEquals("Values do not match", attrValue, Integer.parseInt(attrValueRest)); else if(attrType.equals("long")) assertEquals("Values do not match", attrValue, Long.parseLong(attrValueRest)); else assertEquals("Values do not match", attrValue, attrValueRest); } }