Java Code Examples for org.jboss.shrinkwrap.api.spec.EnterpriseArchive#getAsType()

The following examples show how to use org.jboss.shrinkwrap.api.spec.EnterpriseArchive#getAsType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BuildTest.java    From pnc with Apache License 2.0 5 votes vote down vote up
@Deployment
public static EnterpriseArchive deploy() {
    final EnterpriseArchive ear = Deployments.testEarForInContainerTest(BuildTest.class);
    Deployments.addBuildExecutorMock(ear);
    JavaArchive coordinatorJar = ear.getAsType(JavaArchive.class, Deployments.COORDINATOR_JAR);
    coordinatorJar.addAsManifestResource("beans-use-mock-remote-clients.xml", "beans.xml");
    coordinatorJar.addClass(RemoteBuildsCleanerMock.class);
    return ear;
}
 
Example 2
Source File: Deployments.java    From pnc with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param classes to add to the deployment
 * @return
 */
public static EnterpriseArchive testEarForInContainerTest(Class<?>... classes) {
    EnterpriseArchive ear = testEarForInContainerTest();
    WebArchive restWar = ear.getAsType(WebArchive.class, "/rest-new.war");
    restWar.addClasses(classes);
    return ear;
}
 
Example 3
Source File: Deployments.java    From pnc with Apache License 2.0 5 votes vote down vote up
private static WebArchive prepareRestArchive(EnterpriseArchive ear) {
    WebArchive restWar = ear.getAsType(WebArchive.class, "/rest-new.war");
    restWar.addAsWebInfResource("WEB-INF/web-new.xml", "web.xml");
    restWar.addAsWebInfResource("WEB-INF/jboss-web.xml");
    logger.info("REST archive listing: {}", restWar.toString(true));
    return restWar;
}
 
Example 4
Source File: TemporaryBuildsCleanerTest.java    From pnc with Apache License 2.0 5 votes vote down vote up
@Deployment
public static EnterpriseArchive deploy() {
    EnterpriseArchive enterpriseArchive = Deployments.testEarForInContainerTest(TemporaryBuildsCleanerTest.class);

    JavaArchive coordinator = enterpriseArchive.getAsType(JavaArchive.class, Deployments.COORDINATOR_JAR);
    coordinator.addAsManifestResource("beans-use-mock-remote-clients.xml", "beans.xml");
    coordinator.addClass(RemoteBuildsCleanerMock.class);

    addBuildExecutorMock(enterpriseArchive);

    logger.info(enterpriseArchive.toString(true));
    return enterpriseArchive;
}
 
Example 5
Source File: BuildPushTest.java    From pnc with Apache License 2.0 5 votes vote down vote up
@Deployment
public static EnterpriseArchive deploy() {
    EnterpriseArchive enterpriseArchive = Deployments.testEar();

    JavaArchive processManager = enterpriseArchive.getAsType(JavaArchive.class, Deployments.CAUSEWAY_CLIENT_JAR);
    processManager.deleteClass(DefaultCausewayClient.class);
    processManager.addClass(CausewayClientMock.class);

    processManager.addAsManifestResource("beans-use-mock-remote-clients.xml", "beans.xml");

    addBuildExecutorMock(enterpriseArchive);

    return enterpriseArchive;
}
 
Example 6
Source File: Deployments.java    From pnc with Apache License 2.0 4 votes vote down vote up
private static void addTestPersistenceXml(EnterpriseArchive enterpriseArchive) {
    JavaArchive datastoreJar = enterpriseArchive.getAsType(JavaArchive.class, "/datastore.jar");
    datastoreJar.addAsManifestResource("test-ds.xml", "persistence.xml");
}
 
Example 7
Source File: Deployments.java    From pnc with Apache License 2.0 4 votes vote down vote up
public static void addBuildExecutorMock(EnterpriseArchive enterpriseArchive) {
    JavaArchive jar = enterpriseArchive.getAsType(JavaArchive.class, EXECUTOR_JAR);

    jar.deleteClass(DefaultBuildExecutor.class);

    jar.addPackage(BuildExecutorMock.class.getPackage());
    jar.addClass(BuildDriverResultMock.class);
    jar.addClass(RepositoryManagerResultMock.class);
    jar.addClass(ArtifactBuilder.class);

    jar.addAsManifestResource("beans-use-mock-remote-clients.xml", "beans.xml");

    logger.info(jar.toString(true));

    enterpriseArchive.addAsModule(jar);

}
 
Example 8
Source File: DeploymentFactoryFuncTest.java    From knox with Apache License 2.0 4 votes vote down vote up
@Test( timeout = MEDIUM_TIMEOUT )
public void testDeploymentWithServicesAndApplications() throws Exception {
  LOG_ENTER();
  GatewayTestConfig config = new GatewayTestConfig();
  File targetDir = new File(System.getProperty("user.dir"), "target");
  File gatewayDir = new File(targetDir, "gateway-home-" + UUID.randomUUID());
  gatewayDir.mkdirs();
  config.setGatewayHomeDir(gatewayDir.getAbsolutePath());
  File deployDir = new File(config.getGatewayDeploymentDir());
  deployDir.mkdirs();
  URL serviceUrl = TestUtils.getResourceUrl( DeploymentFactoryFuncTest.class, "test-apps/minimal-test-app/service.xml" );
  File serviceFile = new File( serviceUrl.toURI() );
  File appsDir = serviceFile.getParentFile().getParentFile();
  config.setGatewayApplicationsDir(appsDir.getAbsolutePath());

  DefaultGatewayServices srvcs = new DefaultGatewayServices();
  Map<String, String> options = new HashMap<>();
  options.put("persist-master", "false");
  options.put("master", "password");
  try {
    DeploymentFactory.setGatewayServices(srvcs);
    srvcs.init(config, options);
  } catch (ServiceLifecycleException e) {
    e.printStackTrace(); // I18N not required.
  }

  Topology topology = new Topology();
  topology.setName( "test-topology" );

  Application app;

  topology.setName( "test-cluster" );
  Service service = new Service();
  service.setRole( "WEBHDFS" );
  service.addUrl( "http://localhost:50070/test-service-url" );
  topology.addService( service );

  app = new Application();
  app.setName( "minimal-test-app" );
  app.addUrl( "/minimal-test-app-path-one" );
  topology.addApplication( app );

  app.setName( "minimal-test-app" );
  app.addUrl( "/minimal-test-app-path-two" );
  topology.addApplication( app );

  EnterpriseArchive archive = DeploymentFactory.createDeployment( config, topology );
  assertThat( archive, notNullValue() );

  Document doc;
  org.jboss.shrinkwrap.api.Node node;

  node = archive.get( "META-INF/topology.xml" );
  assertThat( "Find META-INF/topology.xml", node, notNullValue() );
  doc = XmlUtils.readXml( node.getAsset().openStream() );
  assertThat( "Parse META-INF/topology.xml", doc, notNullValue() );

  node = archive.get( "%2F" );
  assertThat( "Find %2F", node, notNullValue() );
  node = archive.get( "%2F/WEB-INF/gateway.xml" );
  assertThat( "Find %2F/WEB-INF/gateway.xml", node, notNullValue() );
  doc = XmlUtils.readXml( node.getAsset().openStream() );
  assertThat( "Parse %2F/WEB-INF/gateway.xml", doc, notNullValue() );

  WebArchive war = archive.getAsType( WebArchive.class, "%2Fminimal-test-app-path-one" );
  assertThat( "Find %2Fminimal-test-app-path-one", war, notNullValue() );
  node = war.get( "/WEB-INF/gateway.xml" );
  assertThat( "Find %2Fminimal-test-app-path-one/WEB-INF/gateway.xml", node, notNullValue() );
  doc = XmlUtils.readXml( node.getAsset().openStream() );
  assertThat( "Parse %2Fminimal-test-app-path-one/WEB-INF/gateway.xml", doc, notNullValue() );

  war = archive.getAsType( WebArchive.class, "%2Fminimal-test-app-path-two" );
  assertThat( "Find %2Fminimal-test-app-path-two", war, notNullValue() );
  node = war.get( "/WEB-INF/gateway.xml" );
  assertThat( "Find %2Fminimal-test-app-path-two/WEB-INF/gateway.xml", node, notNullValue() );
  doc = XmlUtils.readXml( node.getAsset().openStream() );
  assertThat( "Parse %2Fminimal-test-app-path-two/WEB-INF/gateway.xml", doc, notNullValue() );

  LOG_EXIT();
}
 
Example 9
Source File: Deployments.java    From pnc with Apache License 2.0 3 votes vote down vote up
private static void addKeycloakServiceClientMock(EnterpriseArchive enterpriseArchive) {
    JavaArchive jar = enterpriseArchive.getAsType(JavaArchive.class, AUTH_JAR);

    jar.deleteClass(DefaultKeycloakServiceClient.class);
    jar.addClass(KeycloakServiceClientMock.class);

    jar.addAsManifestResource("beans-use-mock-remote-clients.xml", "beans.xml");

    logger.info(jar.toString(true));

    enterpriseArchive.addAsModule(jar);
}