/** * Check is this should run as client. * <p/> * Verify @Deployment.testable vs @RunAsClient on Class or Method level */ private static boolean isRunAsClient(Deployment deployment, Class<?> testClass, Method testMethod) { boolean runAsClient = true; if (deployment != null) { runAsClient = !deployment.getDescription().testable(); runAsClient = !deployment.isDeployed() || runAsClient; if (testMethod.isAnnotationPresent(RunAsClient.class)) { runAsClient = true; } else if (testClass.isAnnotationPresent(RunAsClient.class)) { runAsClient = true; } } return runAsClient; }
/** * Check is this should run as client. * <p/> * Verify @Deployment.testable vs @RunAsClient on Class or Method level */ public static boolean isRunAsClient(Deployment deployment, Class<?> testClass, Method testMethod) { boolean runAsClient = true; if (deployment != null) { runAsClient = !deployment.getDescription().testable(); runAsClient = !deployment.isDeployed() || runAsClient; if (testMethod.isAnnotationPresent(RunAsClient.class)) { runAsClient = true; } else if (testClass.isAnnotationPresent(RunAsClient.class)) { runAsClient = true; } } return runAsClient; }
/** * Returns if the given test should run as client. * <p> * Verify @Deployment.testable vs @RunAsClient on Class or Method level */ public static boolean isRunAsClient(Deployment deployment, TestClass testClass, Method testMethod) { boolean runAsClient = true; if (deployment != null) { runAsClient = deployment.getDescription().testable() ? false : true; runAsClient = deployment.isDeployed() ? runAsClient : true; if (testMethod.isAnnotationPresent(RunAsClient.class)) { runAsClient = true; } else if (testClass.isAnnotationPresent(RunAsClient.class)) { runAsClient = true; } } return runAsClient; }
/** * Returns if the given test should run as client. * <p> * Verify @Deployment.testable vs @RunAsClient on Class or Method level */ public static boolean isRunAsClient(Deployment deployment, TestClass testClass, Method testMethod) { boolean runAsClient = true; if (deployment != null) { runAsClient = deployment.getDescription().testable() ? false : true; runAsClient = deployment.isDeployed() ? runAsClient : true; if (testMethod.isAnnotationPresent(RunAsClient.class)) { runAsClient = true; } else if (testClass.isAnnotationPresent(RunAsClient.class)) { runAsClient = true; } } return runAsClient; }
@Override public InputStream getDeployment(String name) { DeploymentScenario scenario = deploymentScenario.get(); if (scenario == null) { throw new IllegalArgumentException("No deployment scenario in context"); } Deployment deployment = scenario.deployment(new DeploymentTargetDescription(name)); if (deployment == null) { throw new IllegalArgumentException("No deployment in context found with name " + name); } DeploymentDescription description = deployment.getDescription(); if (description.isArchiveDeployment()) { Archive<?> archive = description.testable() ? description.getTestableArchive() : description.getArchive(); return archive.as(ZipExporter.class).exportAsInputStream(); } else { return new ByteArrayInputStream(description.getDescriptor().exportAsString().getBytes()); } } }
@Test public void shouldExecuteLocalIfDeploymentIsTestableButNotDeployed() throws Exception { when(deploymentDescriptor.testable()).thenReturn(true); when(deployment.isDeployed()).thenReturn(false); // override @Before setup fire(test("methodLevelRunModeDefault", new ClassLevelRunModeDefault())); assertEventFired(LocalExecutionEvent.class, 1); }
@Test public void shouldExecuteLocalIfDeploymentIsTestableButNotDeployed() throws Exception { when(deploymentDescriptor.testable()).thenReturn(true); when(deployment.isDeployed()).thenReturn(false); // override @Before setup fire(test("methodLevelRunModeDefault", new ClassLevelRunModeDefault())); assertEventFired(LocalExecutionEvent.class, 1); }
@Test public void shouldExecuteLocalIfDeploymentIsTestableAndClassRunModeAsClient() throws Exception { when(deploymentDescriptor.testable()).thenReturn(true); fire(test("methodLevelRunModeDefault", new ClassLevelRunModeAsClient())); assertEventFired(LocalExecutionEvent.class, 1); }
@Test public void shouldExecuteLocalIfDeploymentIsTestableAndClassRunModeAsClient() throws Exception { when(deploymentDescriptor.testable()).thenReturn(true); fire(test("methodLevelRunModeDefault", new ClassLevelRunModeAsClient())); assertEventFired(LocalExecutionEvent.class, 1); }
@Test public void shouldExecuteLocalIfDeploymentIsTestableAndMethodRunModeAsClient() throws Exception { when(deploymentDescriptor.testable()).thenReturn(true); fire(test("methodLevelRunModeAsClient", new ClassLevelRunModeDefault())); assertEventFired(LocalExecutionEvent.class, 1); }
/** * Verifies that deployments for Warp tests are all testable */ public void verifyWarpDeployment(@Observes DeploymentScenario deploymentScenario) { if (WarpCommons.isWarpTest(testClass.get().getJavaClass())) { for (Deployment deployment : deploymentScenario.deployments()) { DeploymentDescription description = deployment.getDescription(); if (!description.testable()) { throw new IllegalArgumentException( "Warp deployments must be testable: " + testClass.get().getJavaClass() + " - check that you have @Deployment(testable=true)"); } } } } }
@Test public void shouldExecuteRemoteIfDeploymentIsTestableAndDeployed() throws Exception { when(deploymentDescriptor.testable()).thenReturn(true); fire(test("methodLevelRunModeDefault", new ClassLevelRunModeDefault())); assertEventFired(RemoteExecutionEvent.class, 1); }
@Test public void shouldExecuteLocalIfDeploymentIsTestableAndMethodRunModeAsClient() throws Exception { when(deploymentDescriptor.testable()).thenReturn(true); fire(test("methodLevelRunModeAsClient", new ClassLevelRunModeDefault())); assertEventFired(LocalExecutionEvent.class, 1); }
@Test public void shouldExecuteRemoteIfDeploymentIsTestableAndDeployed() throws Exception { when(deploymentDescriptor.testable()).thenReturn(true); fire(test("methodLevelRunModeDefault", new ClassLevelRunModeDefault())); assertEventFired(RemoteExecutionEvent.class, 1); }
@Test public void shouldExecuteLocalIfDeploymentIsNotTestable() throws Exception { when(deploymentDescriptor.testable()).thenReturn(false); fire(test("methodLevelRunModeDefault", new ClassLevelRunModeDefault())); assertEventFired(LocalExecutionEvent.class, 1); }
@Test public void shouldExecuteLocalIfDeploymentIsNotTestable() throws Exception { when(deploymentDescriptor.testable()).thenReturn(false); fire(test("methodLevelRunModeDefault", new ClassLevelRunModeDefault())); assertEventFired(LocalExecutionEvent.class, 1); }
@Test public void shouldReadExpectedAndOverrideDeploymentWhenTestable() { List<DeploymentDescription> scenario = generate(ExpectedDeploymentExceptionSetTestable.class); Assert.assertNotNull(scenario); Assert.assertEquals( "Verify all deployments were found", 1, scenario.size()); DeploymentDescription deploymentOne = scenario.get(0); Assert.assertEquals(true, deploymentOne.testable()); Assert.assertTrue(Validate.isArchiveOfType(JavaArchive.class, deploymentOne.getArchive())); Assert.assertEquals(Exception.class, deploymentOne.getExpectedException()); }
@Test public void shouldReadExpectedAndOverrideDeployment() { List<DeploymentDescription> scenario = generate(ExpectedDeploymentExceptionSet.class); Assert.assertNotNull(scenario); Assert.assertEquals( "Verify all deployments were found", 1, scenario.size()); DeploymentDescription deploymentOne = scenario.get(0); Assert.assertEquals(false, deploymentOne.testable()); Assert.assertTrue(Validate.isArchiveOfType(JavaArchive.class, deploymentOne.getArchive())); Assert.assertEquals(Exception.class, deploymentOne.getExpectedException()); }
@Test public void shouldReadExpectedAndOverrideDeploymentWhenTestable() { List<DeploymentDescription> scenario = generate(ExpectedDeploymentExceptionSetTestable.class); Assert.assertNotNull(scenario); Assert.assertEquals( "Verify all deployments were found", 1, scenario.size()); DeploymentDescription deploymentOne = scenario.get(0); Assert.assertEquals(true, deploymentOne.testable()); Assert.assertTrue(Validate.isArchiveOfType(JavaArchive.class, deploymentOne.getArchive())); Assert.assertEquals(Exception.class, deploymentOne.getExpectedException()); }
@Test public void shouldReadExpectedAndOverrideDeployment() { List<DeploymentDescription> scenario = generate(ExpectedDeploymentExceptionSet.class); Assert.assertNotNull(scenario); Assert.assertEquals( "Verify all deployments were found", 1, scenario.size()); DeploymentDescription deploymentOne = scenario.get(0); Assert.assertEquals(false, deploymentOne.testable()); Assert.assertTrue(Validate.isArchiveOfType(JavaArchive.class, deploymentOne.getArchive())); Assert.assertEquals(Exception.class, deploymentOne.getExpectedException()); }