use of org.apache.karaf.instance.core.InstanceService in project karaf by apache.
the class InstanceServiceMBeanImplTest method testStopInstance.
public void testStopInstance() throws Exception {
Instance inst = EasyMock.createMock(Instance.class);
inst.stop();
EasyMock.expectLastCall();
EasyMock.replay(inst);
InstanceService instanceService = EasyMock.createMock(InstanceService.class);
EasyMock.expect(instanceService.getInstance("test instance")).andReturn(inst);
EasyMock.replay(instanceService);
InstancesMBean instanceServiceMBean = new InstancesMBeanImpl(instanceService);
instanceServiceMBean.stopInstance("test instance");
EasyMock.verify(instanceService);
EasyMock.verify(inst);
}
use of org.apache.karaf.instance.core.InstanceService in project karaf by apache.
the class InstancePluginTest method testDoPostCreate.
public void testDoPostCreate() throws Exception {
InstanceSettings instanceSettings = new InstanceSettings(123, 456, 789, null, null, Collections.singletonList("http://someURL"), Arrays.asList("abc", "def"));
InstanceService instanceService = EasyMock.createMock(InstanceService.class);
EasyMock.expect(instanceService.createInstance("instance1", instanceSettings, false)).andReturn(null);
EasyMock.expect(instanceService.getInstances()).andReturn(new Instance[] {}).anyTimes();
EasyMock.replay(instanceService);
InstancePlugin ap = new InstancePlugin();
ap.setInstanceService(instanceService);
final Map<String, String> params = new HashMap<>();
params.put("action", "create");
params.put("name", "instance1");
params.put("sshPort", "123");
params.put("rmiRegistryPort", "456");
params.put("rmiServerPort", "789");
params.put("featureURLs", "http://someURL");
params.put("features", "abc,def");
HttpServletRequest req = EasyMock.createMock(HttpServletRequest.class);
EasyMock.expect(req.getParameter(EasyMock.anyObject())).andAnswer(() -> params.get(EasyMock.getCurrentArguments()[0])).anyTimes();
HttpServletResponse res = EasyMock.createNiceMock(HttpServletResponse.class);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintWriter pw = new PrintWriter(baos);
EasyMock.expect(res.getWriter()).andReturn(pw);
EasyMock.replay(req);
EasyMock.replay(res);
ap.doPost(req, res);
EasyMock.verify(instanceService);
// Check that the operation has succeeded. This will cause some information to be written to
// the outputstream...
pw.flush();
String s = new String(baos.toByteArray());
assertTrue(s.contains("instance"));
}
use of org.apache.karaf.instance.core.InstanceService in project karaf by apache.
the class InstanceServiceMBeanImplTest method testStartInstanceWithJavaOpts.
public void testStartInstanceWithJavaOpts() throws Exception {
Instance inst = EasyMock.createMock(Instance.class);
inst.start("-x -y -z");
EasyMock.expectLastCall();
EasyMock.replay(inst);
InstanceService instanceService = EasyMock.createMock(InstanceService.class);
EasyMock.expect(instanceService.getInstance("test instance")).andReturn(inst);
EasyMock.replay(instanceService);
InstancesMBean instanceServiceMBean = new InstancesMBeanImpl(instanceService);
instanceServiceMBean.startInstance("test instance", "-x -y -z");
EasyMock.verify(instanceService);
EasyMock.verify(inst);
}
use of org.apache.karaf.instance.core.InstanceService in project karaf by apache.
the class InstanceServiceMBeanImplTest method testCreateInstance2.
public void testCreateInstance2() throws Exception {
final InstanceSettings instanceSettings = new InstanceSettings(0, 0, 0, null, null, Collections.emptyList(), Collections.emptyList(), "localhost");
InstanceService instanceService = EasyMock.createMock(InstanceService.class);
EasyMock.expect(instanceService.createInstance("t1", instanceSettings, false)).andReturn(null);
EasyMock.replay(instanceService);
InstancesMBean ab = new InstancesMBeanImpl(instanceService);
assertEquals(-1, ab.createInstance("t1", 0, 0, 0, "", "", "", ""));
}
use of org.apache.karaf.instance.core.InstanceService in project karaf by apache.
the class InstanceServiceMBeanImplTest method testDestroyInstance.
public void testDestroyInstance() throws Exception {
Instance inst = EasyMock.createMock(Instance.class);
inst.destroy();
EasyMock.expectLastCall();
EasyMock.replay(inst);
InstanceService instanceService = EasyMock.createMock(InstanceService.class);
EasyMock.expect(instanceService.getInstance("test instance")).andReturn(inst);
EasyMock.replay(instanceService);
InstancesMBean instanceServiceMBean = new InstancesMBeanImpl(instanceService);
instanceServiceMBean.destroyInstance("test instance");
EasyMock.verify(instanceService);
EasyMock.verify(inst);
}
Aggregations