Exemplo n.º 1
0
  @Deployment
  public static WebArchive createDeployment() {
    // The servlet protocol relies on the war being called test.war
    WebArchive war = ShrinkWrapUtils.createWebArchive("jsf-example.war", JSFTestCase.class);
    war.addWebResource(EmptyAsset.INSTANCE, "beans.xml")
        .addManifestResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"))
        .add(
            new Asset() {
              @Override
              public InputStream openStream() {
                try {
                  return new ByteArrayInputStream(
                      "org.jboss.arquillian.junit.JUnitTestRunner".getBytes("UTF-8"));
                } catch (UnsupportedEncodingException e) {
                  throw new RuntimeException(e);
                }
              }
            },
            "META-INF/services/" + TestRunner.class.getName())
        .addManifestResource(jsfunitFacesConfigXml(), "faces-config.xml")
        .addManifestResource("arquillian/web-fragment.xml", "web-fragment.xml");

    // System.out.println(war.toString(true)); // for debugging
    return war;
  }
  @Test
  public void testDeploymentFileApi() throws Exception {
    final JavaArchive archive =
        ShrinkWrapUtils.createJavaArchive(
            "servermodule/test-deployment.sar", Simple.class.getPackage());
    final ServerDeploymentManager manager =
        ServerDeploymentManager.Factory.create(InetAddress.getByName("localhost"), 9999);
    final File dir = new File("target/archives");
    dir.mkdirs();
    final File file = new File(dir, "test-deployment.sar");
    archive.as(ZipExporter.class).exportZip(file, true);

    testDeployments(
        new DeploymentExecutor() {

          @Override
          public void initialDeploy() throws IOException {
            manager.execute(
                manager
                    .newDeploymentPlan()
                    .add("test-deployment.sar", file)
                    .deploy("test-deployment.sar")
                    .build());
          }

          @Override
          public void fullReplace() throws IOException {
            manager.execute(
                manager.newDeploymentPlan().replace("test-deployment.sar", file).build());
          }

          @Override
          public void undeploy() {
            manager.execute(
                manager
                    .newDeploymentPlan()
                    .undeploy("test-deployment.sar")
                    .remove("test-deployment.sar")
                    .build());
          }
        });
  }
Exemplo n.º 3
0
 @Deployment(testable = false)
 public static Archive<?> getDeployment() {
   return ShrinkWrapUtils.createWebArchive(
       "demos/ws-example.war", EndpointImpl.class.getPackage());
 }
  @Test
  public void testFilesystemDeployment() throws Exception {
    final JavaArchive archive =
        ShrinkWrapUtils.createJavaArchive(
            "servermodule/test-deployment.sar", Simple.class.getPackage());
    final File dir = new File("target/archives");
    dir.mkdirs();
    final File file = new File(dir, "test-deployment.sar");
    archive.as(ZipExporter.class).exportZip(file, true);

    final File deployDir = new File("target", "deployments");
    cleanFile(deployDir);
    deployDir.mkdirs();
    Assert.assertTrue(deployDir.exists());

    ModelControllerClient client =
        ModelControllerClient.Factory.create(InetAddress.getByName("localhost"), 9999);
    ModelNode add = new ModelNode();
    add.get(OP).set(ADD);
    ModelNode addr = new ModelNode();
    addr.add("subsystem", "deployment-scanner");
    addr.add("scanner", "test");
    add.get(OP_ADDR).set(addr);
    add.get("path").set(deployDir.getAbsolutePath());
    add.get("scan-enabled").set(true);
    add.get("scan-interval").set(1000);

    ModelNode result = client.execute(add);
    Assert.assertEquals(
        ModelDescriptionConstants.SUCCESS,
        result.require(ModelDescriptionConstants.OUTCOME).asString());

    try {
      final File target = new File(deployDir, "test-deployment.sar");
      final File deployed = new File(deployDir, "test-deployment.sar.isdeployed");
      Assert.assertFalse(target.exists());

      testDeployments(
          new DeploymentExecutor() {
            @Override
            public void initialDeploy() throws IOException {
              // Copy file to deploy directory
              final InputStream in = new BufferedInputStream(new FileInputStream(file));
              try {
                final OutputStream out = new BufferedOutputStream(new FileOutputStream(target));
                try {
                  int i = in.read();
                  while (i != -1) {
                    out.write(i);
                    i = in.read();
                  }
                } finally {
                  StreamUtils.safeClose(out);
                }
              } finally {
                StreamUtils.safeClose(in);
              }
              // Create the .dodeploy file
              final File dodeploy = new File(deployDir, "test-deployment.sar.dodeploy");
              final OutputStream out = new BufferedOutputStream(new FileOutputStream(dodeploy));
              try {
                out.write("test-deployment.sar".getBytes());
              } finally {
                StreamUtils.safeClose(out);
              }
              Assert.assertTrue(dodeploy.exists());
            }

            @Override
            public void fullReplace() throws IOException {
              // The test is going to call this as soon as the deployment sends a notification
              // but often before the scanner has completed the process and deleted the
              // .dodpeloy put down by initialDeploy(). So pause a bit to let that complete
              // so we don't end up having our own file deleted
              final File dodeploy = new File(deployDir, "test-deployment.sar.dodeploy");
              for (int i = 0; i < 100; i++) {
                if (!dodeploy.exists()) {
                  break;
                }
                // Wait for the last action to complete :(
                try {
                  Thread.sleep(10);
                } catch (InterruptedException e) {
                  Thread.currentThread().interrupt();
                  break;
                }
              }
              // Copy file to deploy directory again
              initialDeploy();
            }

            @Override
            public void undeploy() {
              final File dodeploy = new File(deployDir, "test-deployment.sar.dodeploy");
              for (int i = 0; i < 100; i++) {
                if (!dodeploy.exists() && deployed.exists()) {
                  break;
                }
                // Wait for the last action to complete :(
                try {
                  Thread.sleep(10);
                } catch (InterruptedException e) {
                  Thread.currentThread().interrupt();
                  break;
                }
              }
              // Delete file from deploy directory
              deployed.delete();
            }
          });
    } finally {
      try {
        client.execute(result.get(ModelDescriptionConstants.COMPENSATING_OPERATION));
      } catch (Exception e) {
        client.close();
      }
    }
  }