PMMLRestResourceGenerator { void setPredictionModelName(ClassOrInterfaceDeclaration template) { template.getMethodsByName("pmml").get(0) .getBody().orElseThrow(() -> new RuntimeException("")) .getStatement(0).asExpressionStmt().getExpression() .asVariableDeclarationExpr() .getVariable(0) .getInitializer().orElseThrow(() -> new RuntimeException("")) .asMethodCallExpr() .getArgument(0).asStringLiteralExpr().setString(kiePMMLModel.getName()); } PMMLRestResourceGenerator(KiePMMLModel model, String appCanonicalName); String generate(); String getNameURL(); KiePMMLModel getKiePMMLModel(); PMMLRestResourceGenerator withDependencyInjection(DependencyInjectionAnnotator annotator); String className(); String generatedFilePath();  }
@Test void setPredictionModelName() { assertEquals(1, template.getMethodsByName("pmml").size()); Optional<BlockStmt> retrievedOpt = template.getMethodsByName("pmml").get(0).getBody(); assertTrue(retrievedOpt.isPresent()); BlockStmt retrieved = retrievedOpt.get(); assertTrue(retrieved.getStatement(0) instanceof ExpressionStmt); assertTrue(retrieved.getStatement(0).asExpressionStmt().getExpression() instanceof VariableDeclarationExpr); VariableDeclarationExpr variableDeclarationExpr = retrieved.getStatement(0).asExpressionStmt().getExpression().asVariableDeclarationExpr(); Optional<Expression> expressionOpt = variableDeclarationExpr.getVariable(0).getInitializer(); assertTrue(expressionOpt.isPresent()); assertTrue(expressionOpt.get() instanceof MethodCallExpr); MethodCallExpr methodCallExpr = expressionOpt.get().asMethodCallExpr(); assertTrue(methodCallExpr.getArgument(0) instanceof StringLiteralExpr); pmmlRestResourceGenerator.setPredictionModelName(template); try { assertEquals(KIE_PMML_MODEL.getName(), methodCallExpr.getArgument(0).asStringLiteralExpr().asString()); } catch (Exception e) { fail(e); } }