Source:
public void testExecWithJobAndStackService() throws ClassNotFoundException, URISyntaxException, InterruptedException{ User root = UserResource.Root; assertNotNull(root); CloudResourceTestWrapper cpr = new CloudResourceTestWrapper(); cpr.addSecurityContext(null); AccountResource accr = PowerMockito.spy(new AccountResource()); AccountManager accm = PowerMockito.mock(AccountManager.class); PowerMockito.mockStatic(AccountManager.class); try { setFinalStatic(AccountResource.class.getField("dao"), accm); } catch (Exception e) { e.printStackTrace(); } List<Variable> context = new ArrayList<Variable>(); Account acc1 = new Account("HP1", null, null, "cloud1", null, root.getUri(), false); acc1.setUri(new URI("<LINK_0>")); acc1.setId((long) 1); Variable var = new Variable("account",acc1.getUri()); context.add(var); PowerMockito.when(accm.load(new URI("<LINK_0>"), root)).thenReturn(acc1); Response result = cpr.exec("StackService", "testingExec", "", "", context); System.out.println(result.getMetadata()); URI processId = (URI) result.getMetadata().getFirst("Location"); CloudProcess p = cpr.dao.load(processId); System.out.println(p); StackServiceAction sAction = (StackServiceAction) ActionResource.dao.load(p.getAction()); assertEquals("Action has wrong name", sAction.getName(), "testingExec"); assertEquals("Process has a father",p.getParent(),null); result = cpr.exec("Job", "deployTest", "NShell ", p.getUri().toString(), context); processId = (URI) result.getMetadata().getFirst("Location"); CloudProcess pSon = cpr.dao.load(processId); assertEquals("Process don't has the right father",pSon.getParent(),p.getUri()); sAction = (StackServiceAction) ActionResource.dao.load(p.getAction()); assertEquals("Stack not added", sAction.getStacks().get(0).getName(), "deployTest" ); assertEquals("List size different than expected", sAction.getStacks().size(), 1 ); }

Target:
public void testExecWithJobAndStackService() throws ClassNotFoundException, URISyntaxException, InterruptedException{ User root = UserResource.Root; assertNotNull(root); CloudResourceTestWrapper cpr = new CloudResourceTestWrapper(); cpr.addSecurityContext(null); AccountManager accm = PowerMockito.mock(AccountManager.class); PowerMockito.mockStatic(AccountManager.class); try { setFinalStatic(AccountResource.class.getField("dao"), accm); } catch (Exception e) { e.printStackTrace(); } List<Variable> context = new ArrayList<Variable>(); Account acc1 = new Account("HP1", null, null, "cloud1", null, root.getUri(), false); acc1.setUri(new URI("<LINK_0>")); acc1.setId((long) 1); Variable var = new Variable("account",acc1.getUri()); context.add(var); PowerMockito.when(accm.load(new URI("<LINK_0>"), root)).thenReturn(acc1); Response result = cpr.exec("StackService", "testingExec", "", "", context); System.out.println(result.getMetadata()); URI processId = (URI) result.getMetadata().getFirst("Location"); CloudProcess p = cpr.dao.load(processId); System.out.println(p); StackServiceAction sAction = (StackServiceAction) ActionResource.dao.load(p.getAction()); assertEquals("Action has wrong name", sAction.getName(), "testingExec"); assertEquals("Process has a father",p.getParent(),null); result = cpr.exec("Job", "deployTest", "NShell ", p.getUri().toString(), context); processId = (URI) result.getMetadata().getFirst("Location"); CloudProcess pSon = cpr.dao.load(processId); assertEquals("Process don't has the right father",pSon.getParent(),p.getUri()); sAction = (StackServiceAction) ActionResource.dao.load(p.getAction()); assertEquals("Stack not added", sAction.getStacks().get(0).getName(), "deployTest" ); assertEquals("List size different than expected", sAction.getStacks().size(), 1 ); }