Esempio n. 1
0
 public static void main(String[] args) {
   WeldContainer weldContainer = new Weld().initialize();
   Car car = weldContainer.instance().select(Car.class).get();
   weldContainer.instance().select(PoliceStation.class).get();
   weldContainer.instance().select(AARoadsideAssistant.class).get();
   car.getDriver().drive();
 }
Esempio n. 2
0
  @Before
  public void setUp() {
    WeldContainer container = new Weld().initialize();
    this.keeper = container.instance().select(Keeper.class).get();

    this.manager = container.instance().select(EntityManager.class).get();
    this.transaction = this.manager.getTransaction();
    this.transaction.begin();
  }
 @Test
 public void shouldCheckNumberIsThirteenDigits() {
   LibroService36 bookService = container.instance().select(LibroService36.class).get();
   Libro36 book = bookService.createBook("H2G2", 12.5f, "Geeky scifi Book");
   assertTrue(book.getIsbn().startsWith("8"));
   bookService.deleteBook(book);
 }
  @Override
  public String execute(CliContext context) {
    StringBuffer result = new StringBuffer();
    WeldContainer container = context.getContainer();

    OrganizationalUnitService organizationalUnitService =
        container.instance().select(OrganizationalUnitService.class).get();

    InputReader input = context.getInput();
    System.out.print(">>Organizational Unit name:");
    String name = input.nextLine();

    OrganizationalUnit organizationalUnit = organizationalUnitService.getOrganizationalUnit(name);
    if (organizationalUnit == null) {
      return "No Organizational Unit " + name + " was found";
    }
    System.out.print(">>Security roles (comma separated list):");
    String rolesIn = input.nextLine();
    if (rolesIn.trim().length() > 0) {

      String[] roles = rolesIn.split(",");
      for (String role : roles) {
        organizationalUnitService.removeRole(organizationalUnit, role);
        result.append(
            "Role "
                + role
                + " removed successfully from Organizational Unit "
                + organizationalUnit.getName()
                + "\n");
      }
    }

    return result.toString();
  }
  @Override
  public String execute(CliContext context) {
    StringBuffer result = new StringBuffer();
    WeldContainer container = context.getContainer();

    RepositoryService repositoryService =
        container.instance().select(RepositoryService.class).get();

    InputReader input = context.getInput();
    System.out.print(">>Repository alias:");
    String alias = input.nextLine();

    Repository repo = repositoryService.getRepository(alias);
    if (repo == null) {
      return "No repository " + alias + " was found";
    }
    System.out.print(">>Security groups (comma separated list):");
    String groupsIn = input.nextLine();
    if (groupsIn.trim().length() > 0) {

      String[] groups = groupsIn.split(",");
      for (String group : groups) {
        if (repo.getGroups().contains(group)) {
          continue;
        }
        repositoryService.addGroup(repo, group);
        result.append(
            "Group " + group + " added successfully to repository " + repo.getAlias() + "\n");
      }
    }

    return result.toString();
  }
Esempio n. 6
0
 public static void main(String[] args) {
   // TODO Auto-generated method stub
   Weld weld = new Weld();
   WeldContainer container = weld.initialize();
   BookService bookService = container.instance().select(BookService.class).get();
   System.out.println("Запсукаемся...");
   bookService.test();
 }
 public void startUp() {
   // As per BRDRLPersistence.marshalRHS()
   String dateFormatProperty = System.getProperty("drools.dateformat");
   if (dateFormatProperty == null || dateFormatProperty.length() == 0)
     System.setProperty("drools.dateformat", "dd-MM-yyyy");
   weld = new Weld();
   weldContainer = weld.initialize();
   exporter = weldContainer.instance().select(JcrExporter.class).get();
 }
  @Test
  public void shouldCheckNumberIsMOCK() {
    Weld weld = new Weld();
    WeldContainer container = weld.initialize();

    BookService bookService = container.instance().select(BookService.class).get();
    Book book = bookService.createBook("title", 19.99F, "best book");

    Assert.assertTrue(book.getNumber().startsWith("Mock"));
  }
  @Override
  public String execute(CliContext context) {
    StringBuffer result = new StringBuffer();
    WeldContainer container = context.getContainer();

    OrganizationalUnitService organizationalUnitService =
        container.instance().select(OrganizationalUnitService.class).get();
    RepositoryService repositoryService =
        container.instance().select(RepositoryService.class).get();

    InputReader input = context.getInput();
    System.out.print(">>Organizational Unit name:");
    String name = input.nextLine();

    System.out.print(">>Organizational Unit owner:");
    String owner = input.nextLine();

    System.out.print(">>Default Group Id for this Organizational Unit:");
    String defaultGroupId = input.nextLine();

    System.out.print(">>Repositories (comma separated list):");
    String repos = input.nextLine();
    Collection<Repository> repositories = new ArrayList<Repository>();
    if (repos != null && repos.trim().length() > 0) {
      String[] repoAliases = repos.split(",");
      for (String alias : repoAliases) {
        Repository repo = repositoryService.getRepository(alias);
        if (repo != null) {
          repositories.add(repo);
        } else {
          System.out.println(
              "WARN: Repository with alias " + alias + " does not exists and will be skipped");
        }
      }
    }

    OrganizationalUnit organizationalUnit =
        organizationalUnitService.createOrganizationalUnit(
            name, owner, defaultGroupId, repositories);
    result.append("Organizational Unit " + organizationalUnit.getName() + " successfully created");
    return result.toString();
  }
  @Test
  public void test() {
    WeldContainer weld = new Weld().initialize();
    Instance<CalculatorService> instance = weld.instance().select(CalculatorService.class);
    CalculatorService service = instance.get();

    assertEquals(21, service.sum(Arrays.asList(1, 2, 3, 4, 5, 6)));

    double resultDiv = service.div(42.0, 2.0);
    assertEquals(21.0, resultDiv, 0.0001);
  }
Esempio n. 11
0
  @Test
  public void testGo() {
    Weld w = new Weld();
    WeldContainer wc = w.initialize();

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(baos);

    CDIInstanceExample bean = wc.instance().select(CDIInstanceExample.class).get();
    bean.go(ps);

    ps.close();

    String actual = new String(baos.toByteArray());
    String expected =
        "" + "Dave: Hello, HAL. Do you read me, HAL?" + NL + "HAL: Dave. I read you." + NL;
    assertEquals(expected, actual);

    w.shutdown();
  }
Esempio n. 12
0
  @Test
  @Ignore
  public void test1() {
    final List<String> classes = new ArrayList<String>();
    classes.add(TestClass.class.getName());
    classes.add(TestClassImpl.class.getName());

    Weld weldContainer =
        new Weld() {
          @Override
          protected Deployment createDeployment(
              ResourceLoader resourceLoader, Bootstrap bootstrap) {
            return new TestWeldSEDeployment(resourceLoader, bootstrap, classes);
          }
        };

    WeldContainer weld = weldContainer.initialize();
    TestClass bean = weld.instance().select(TestClass.class).get();

    System.out.println(bean.getKBase1());
  }
  @Override
  public String execute(CliContext context) {
    StringBuffer result = new StringBuffer();
    WeldContainer container = context.getContainer();

    OrganizationalUnitService organizationalUnitService =
        container.instance().select(OrganizationalUnitService.class).get();
    RepositoryService repositoryService =
        container.instance().select(RepositoryService.class).get();
    ExplorerService projectExplorerService =
        container.instance().select(ExplorerService.class).get();

    InputReader input = context.getInput();
    System.out.print(">>Repository alias:");
    String alias = input.nextLine();

    Repository repo = repositoryService.getRepository(alias);
    if (repo == null) {
      return "No repository " + alias + " was found";
    }

    OrganizationalUnit ou = null;
    Collection<OrganizationalUnit> units = organizationalUnitService.getOrganizationalUnits();
    for (OrganizationalUnit unit : units) {
      if (unit.getRepositories().contains(repo)) {
        ou = unit;
        break;
      }
    }
    if (ou == null) {
      return "Could not find Organizational Unit containing repository. Unable to proceed.";
    }

    ArrayList<Project> projects = new ArrayList<Project>();
    ProjectExplorerContentQuery query = new ProjectExplorerContentQuery(ou, repo, "master");
    query.setOptions(new ActiveOptions());
    ProjectExplorerContent content = projectExplorerService.getContent(query);
    projects.addAll(content.getProjects());
    if (projects.size() == 0) {
      return "No projects found in repository " + alias;
    }

    int projectIndex = 0;
    while (projectIndex == 0) {
      System.out.println(">>Select project:");
      for (int i = 0; i < projects.size(); i++) {
        System.out.println((i + 1) + ") " + projects.get(i).getProjectName());
      }
      try {
        projectIndex = Integer.parseInt(input.nextLine());
      } catch (NumberFormatException e) {
        System.out.println("Invalid index");
      }
      if (projectIndex < 1 || projectIndex > projects.size()) {
        projectIndex = 0;
        System.out.println("Invalid index");
      }
    }
    Project project = projects.get(projectIndex - 1);

    result.append("\tProject " + project.getProjectName() + "\n");
    result.append("\t Modules: " + project.getModules() + "\n");
    result.append("\t Root path: " + project.getRootPath().toURI() + "\n");
    result.append("\t Pom path: " + project.getPomXMLPath().toURI() + "\n");

    return result.toString();
  }
Esempio n. 14
0
 @Before
 public void init() {
   this.localeProvider = container.instance().select(LocaleProvider.class).get();
   this.localeProvider.setCurrentLocale(expected.getLocale());
   this.bean = container.instance().select(TestBean.class).get();
 }
Esempio n. 15
0
 @Override
 protected Object createTest() throws Exception {
   return container.instance().select(klass).get();
 }