Skip to content

Commit

Permalink
DROOLS-3978 Move codegen unit tests to kogito-codegen (apache#56)
Browse files Browse the repository at this point in the history
* DROOLS-3978 Add RuleConfigGeneratorTest

* DROOLS-3978 Move codegen unit tests
  • Loading branch information
baldimir committed May 27, 2019
1 parent 22b2bcb commit 7d74437
Show file tree
Hide file tree
Showing 26 changed files with 45 additions and 38 deletions.
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.kie.dmn.submarine.rest.quarkus;
package org.kie.dmn.kogito.rest.quarkus;

import java.io.Serializable;

Expand Down
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.kie.dmn.submarine.rest.quarkus;
package org.kie.dmn.kogito.rest.quarkus;

import java.io.Serializable;
import java.util.ArrayList;
Expand Down
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.kie.dmn.submarine.rest.quarkus;
package org.kie.dmn.kogito.rest.quarkus;

import java.io.Serializable;

Expand Down
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.kie.dmn.submarine.rest.quarkus;
package org.kie.dmn.kogito.rest.quarkus;

import java.io.Serializable;

Expand Down
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.kie.dmn.submarine.rest.quarkus;
package org.kie.dmn.kogito.rest.quarkus;

import java.io.Serializable;
import java.util.ArrayList;
Expand Down
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.kie.dmn.submarine.rest.quarkus;
package org.kie.dmn.kogito.rest.quarkus;

import java.io.FileReader;
import java.io.IOException;
Expand All @@ -40,11 +40,11 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DMNSubmarineQuarkus {
public class DMNKogitoQuarkus {

private static final Logger LOG = LoggerFactory.getLogger(DMNSubmarineQuarkus.class);
private static final Logger LOG = LoggerFactory.getLogger(DMNKogitoQuarkus.class);

private DMNSubmarineQuarkus() {
private DMNKogitoQuarkus() {
// intentionally private.
}

Expand Down
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.kie.dmn.submarine.rest.quarkus;
package org.kie.dmn.kogito.rest.quarkus;

import java.io.Serializable;

Expand Down
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.kie.dmn.submarine.rest.quarkus;
package org.kie.dmn.kogito.rest.quarkus;

import java.io.Serializable;
import java.util.Collection;
Expand Down
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.kie.dmn.submarine.rest.quarkus;
package org.kie.dmn.kogito.rest.quarkus;

import java.io.Serializable;
import java.util.Arrays;
Expand Down
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.kie.dmn.submarine.rest.quarkus;
package org.kie.dmn.kogito.rest.quarkus;

import java.io.Serializable;
import java.util.ArrayList;
Expand Down
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.kie.dmn.submarine.rest.quarkus;
package org.kie.dmn.kogito.rest.quarkus;

import java.io.Serializable;

Expand Down
2 changes: 1 addition & 1 deletion history/history.adoc
Expand Up @@ -11,7 +11,7 @@ To merge upstream v7 repos used the following commands, for example:
(fix conflicts in .gitignore)
1118 git add .gitignore
1119 git merge --continue
then moved the relevant directories from merge into its relevant submarine/subdirectory,
then moved the relevant directories from merge into its relevant kogito/subdirectory,
for example /bom
and commit the move.

Expand Up @@ -13,7 +13,7 @@
* limitations under the License.
*/

package org.kie.submarine.process.bpmn2;
package org.kie.kogito.process.bpmn2;

import java.util.List;
import java.util.stream.Collectors;
Expand Down
Expand Up @@ -13,7 +13,7 @@
* limitations under the License.
*/

package org.kie.submarine.process.bpmn2;
package org.kie.kogito.process.bpmn2;

import java.util.Map;

Expand Down
Expand Up @@ -13,7 +13,7 @@
* limitations under the License.
*/

package org.kie.submarine.process.bpmn2;
package org.kie.kogito.process.bpmn2;

public class BpmnProcessReaderException extends RuntimeException {

Expand Down
Expand Up @@ -13,7 +13,7 @@
* limitations under the License.
*/

package org.kie.submarine.process.bpmn2;
package org.kie.kogito.process.bpmn2;

import java.util.Collections;
import java.util.HashMap;
Expand Down
Expand Up @@ -54,8 +54,8 @@
import org.kie.kogito.process.impl.CachedWorkItemHandlerConfig;
import org.kie.kogito.process.impl.DefaultProcessEventListenerConfig;
import org.kie.kogito.process.impl.StaticProcessConfig;
import org.kie.submarine.process.bpmn2.BpmnProcess;
import org.kie.submarine.process.bpmn2.BpmnVariables;
import org.kie.kogito.process.bpmn2.BpmnProcess;
import org.kie.kogito.process.bpmn2.BpmnVariables;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Expand Up @@ -67,7 +67,7 @@ public IncrementalRuleCodegen( Path basePath, Collection<File> files, ResourceTy
} else if ( resourceType == ResourceType.DTABLE ) {
pkgDescrConverter = KnowledgeBuilderUtil::dtableToPackageDescr;
} else {
throw new RuntimeException( "Unknown resource type " + resourceType );
throw new IllegalArgumentException( "Unknown resource type " + resourceType );
}
}

Expand Down
Expand Up @@ -56,7 +56,11 @@ public RuleCodegenProject withModuleGenerator(ModuleSourceClass moduleGenerator)
public void writeProjectOutput(MemoryFileSystem trgMfs, ResultsImpl messages) {
super.writeProjectOutput(trgMfs, messages);

moduleGenerator.withCdi(hasCdi());
if (moduleGenerator == null) {
throw new IllegalStateException("Module generator is not specified!");
} else {
moduleGenerator.withCdi(hasCdi());
}

boolean hasRuleUnits = false;

Expand Down
Expand Up @@ -21,17 +21,20 @@
import com.github.javaparser.ast.expr.ObjectCreationExpr;

public class RuleConfigGenerator {
private String ruleEventListenersConfigCLass = DefaultRuleEventListenerConfig.class.getCanonicalName();
private String ruleEventListenersConfigClass = DefaultRuleEventListenerConfig.class.getCanonicalName();

public RuleConfigGenerator ruleEventListenersConfig(String cfg) {
this.ruleEventListenersConfigCLass = cfg;
if (cfg == null) {
throw new IllegalArgumentException("Specified rule listeners config class is undefined (null)!");
}
this.ruleEventListenersConfigClass = cfg;
return this;
}


public ObjectCreationExpr newInstance() {
return new ObjectCreationExpr()
.setType(StaticRuleConfig.class.getCanonicalName())
.addArgument(new ObjectCreationExpr().setType(ruleEventListenersConfigCLass));
.addArgument(new ObjectCreationExpr().setType(ruleEventListenersConfigClass));
}
}
Expand Up @@ -59,7 +59,7 @@ protected Application generateCodeRulesOnly(String... rules) throws Exception {

protected Application generateCode(List<String> processResources, List<String> rulesResources) throws Exception {
ApplicationGenerator appGen =
new ApplicationGenerator("org.kie.submarine.test", new File("target/codegen-tests"))
new ApplicationGenerator(this.getClass().getPackage().getName(), new File("target/codegen-tests"))
.withDependencyInjection(false);

if (!rulesResources.isEmpty()) {
Expand Down Expand Up @@ -98,7 +98,7 @@ protected Application generateCode(List<String> processResources, List<String> r
TestClassLoader cl = new TestClassLoader(this.getClass().getClassLoader(), trgMfs.getMap());

@SuppressWarnings("unchecked")
Class<Application> app = (Class<Application>) Class.forName("org.kie.submarine.test.Application", true, cl);
Class<Application> app = (Class<Application>) Class.forName(this.getClass().getPackage().getName() + ".Application", true, cl);

return app.newInstance();
}
Expand All @@ -109,7 +109,7 @@ private static class TestClassLoader extends URLClassLoader {

public TestClassLoader(ClassLoader parent, Map<String, byte[]> extraClassDefs) {
super(new URL[0], parent);
this.extraClassDefs = new HashMap<String, byte[]>();
this.extraClassDefs = new HashMap<>();

for (Entry<String, byte[]> entry : extraClassDefs.entrySet()) {
this.extraClassDefs.put(entry.getKey().replaceAll("/", ".").replaceFirst("\\.class", ""), entry.getValue());
Expand Down
Expand Up @@ -13,7 +13,7 @@
* limitations under the License.
*/

package org.kie.submarine.codegen;
package org.kie.kogito.codegen;

import java.io.File;
import java.io.IOException;
Expand All @@ -37,6 +37,7 @@
import com.github.javaparser.ast.body.TypeDeclaration;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.kie.kogito.Config;
import org.mockito.Mockito;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -180,7 +181,7 @@ private void assertCompilationUnit(final CompilationUnit compilationUnit, final

assertThat(compilationUnit.getImports()).isNotNull();
assertThat(compilationUnit.getImports()).hasSize(2);
assertThat(compilationUnit.getImports().get(0).getName().toString()).isEqualTo("org.kie.submarine.Config");
assertThat(compilationUnit.getImports().get(0).getName().toString()).isEqualTo(Config.class.getCanonicalName());

assertThat(compilationUnit.getTypes()).isNotNull();
assertThat(compilationUnit.getTypes()).hasSize(1);
Expand Down
Expand Up @@ -13,13 +13,13 @@
* limitations under the License.
*/

package org.kie.submarine.codegen;
package org.kie.kogito.codegen;

import com.github.javaparser.ast.expr.NullLiteralExpr;
import com.github.javaparser.ast.expr.ObjectCreationExpr;
import org.junit.Test;
import org.kie.submarine.StaticConfig;
import org.kie.submarine.codegen.process.config.ProcessConfigGenerator;
import org.kie.kogito.StaticConfig;
import org.kie.kogito.codegen.process.config.ProcessConfigGenerator;
import org.mockito.Mockito;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down
Expand Up @@ -13,7 +13,7 @@
* limitations under the License.
*/

package org.kie.submarine.codegen;
package org.kie.kogito.codegen;

import java.nio.charset.StandardCharsets;

Expand Down
Expand Up @@ -13,10 +13,9 @@
* limitations under the License.
*/

package org.kie.submarine.codegen;
package org.kie.kogito.codegen;

import java.util.Collection;
import java.util.Map;

import com.github.javaparser.ast.body.BodyDeclaration;
import com.github.javaparser.ast.body.MethodDeclaration;
Expand Down
Expand Up @@ -13,7 +13,7 @@
* limitations under the License.
*/

package org.kie.submarine.codegen.metadata;
package org.kie.kogito.codegen.metadata;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down

0 comments on commit 7d74437

Please sign in to comment.