コード例 #1
0
  @Test
  public void testRpcSample() throws Exception {
    CompilationUnit compilationUnit =
        JavaParser.parse(getClass().getResourceAsStream("testRpcSample.java.resource"));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ClassOrInterfaceDeclaration mainType = getMainType(compilationUnit);
    rpcPojosAjGenerator.generateEntity(compilationUnit, mainType, baos);

    byte[] expectedBytes =
        IOUtils.toByteArray(getClass().getResourceAsStream("rpcSample_Aspect.aj.expected"));
    AssertUtils.assertContent(expectedBytes, baos.toByteArray());

    List<BodyDeclaration> members = mainType.getMembers();
    for (BodyDeclaration bodyDeclaration : members) {
      // look for inner classes
      baos = new ByteArrayOutputStream();
      if (bodyDeclaration instanceof ClassOrInterfaceDeclaration) {
        rpcPojosAjGenerator.generatePart(
            compilationUnit,
            (ClassOrInterfaceDeclaration) bodyDeclaration,
            baos,
            mainType.getName());
        String expected =
            ((ClassOrInterfaceDeclaration) bodyDeclaration).getName() + "_Aspect.aj.expected";
        expectedBytes = IOUtils.toByteArray(getClass().getResourceAsStream(expected));
        AssertUtils.assertContent(expectedBytes, baos.toByteArray());
      }
    }
  }
コード例 #2
0
  private void testGenerate(String javaSource, String expectAspect)
      throws IOException, TemplateException, ParseException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    CompilationUnit compilationUnit = JavaParser.parse(getClass().getResourceAsStream(javaSource));

    rpcPojosAjGenerator.generateEntity(compilationUnit, getMainType(compilationUnit), baos);

    byte[] expectedBytes = IOUtils.toByteArray(getClass().getResourceAsStream(expectAspect));

    AssertUtils.assertContent(expectedBytes, baos.toByteArray());
  }
コード例 #3
0
 private void assertSnapshot(TerminalSnapshot terminalSnapshot, String snapshotTextFile)
     throws IOException {
   byte[] expectedBytes = IOUtils.toByteArray(getClass().getResourceAsStream(snapshotTextFile));
   AssertUtils.assertContent(expectedBytes, terminalSnapshot.toString().getBytes());
 }