Skip to content

Commit

Permalink
BPMSPL-165 - Improve REST query infrastructure and capabilities: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Rietveld committed Aug 1, 2015
1 parent 804178c commit b919a69
Show file tree
Hide file tree
Showing 51 changed files with 1,937 additions and 672 deletions.
25 changes: 21 additions & 4 deletions jbpm-audit/pom.xml
Expand Up @@ -66,7 +66,14 @@
<scope>provided</scope>
</dependency>

<!-- Test -->
<!-- TEST -->
<dependency>
<groupId>org.jbpm</groupId>
<artifactId>jbpm-flow-builder</artifactId>
<scope>test</scope>
</dependency>

<!-- Test: persistence -->
<dependency>
<groupId>org.jbpm</groupId>
<artifactId>jbpm-persistence-jpa</artifactId>
Expand Down Expand Up @@ -98,6 +105,14 @@
<artifactId>btm</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jbpm</groupId>
<artifactId>jbpm-query-jpa</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>

<!-- Test: jms -->
<dependency>
<groupId>org.hornetq</groupId>
<artifactId>hornetq-server</artifactId>
Expand All @@ -120,24 +135,26 @@
</exclusions>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.netty</groupId>
<artifactId>netty</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.hornetq</groupId>
<artifactId>hornetq-jms-server</artifactId>
<scope>test</scope>
</dependency>

<!-- Test: logging -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
</dependencies><build>
</dependencies>

<build>
<testResources>
<testResource>
<directory>src/test/resources</directory>
Expand Down
Expand Up @@ -16,7 +16,10 @@

package org.jbpm.process.audit;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down
Expand Up @@ -16,8 +16,12 @@

package org.jbpm.process.audit;

import static org.jbpm.persistence.util.PersistenceUtil.*;
import static org.junit.Assert.*;
import static org.jbpm.persistence.util.PersistenceUtil.JBPM_PERSISTENCE_UNIT_NAME;
import static org.jbpm.persistence.util.PersistenceUtil.cleanUp;
import static org.jbpm.persistence.util.PersistenceUtil.setupWithPoolingDataSource;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.io.InputStreamReader;
import java.io.Reader;
Expand All @@ -27,7 +31,6 @@
import java.util.List;

import org.drools.compiler.builder.impl.KnowledgeBuilderImpl;
import org.drools.core.definitions.InternalKnowledgePackage;
import org.drools.core.impl.EnvironmentFactory;
import org.jbpm.test.util.AbstractBaseTest;
import org.junit.After;
Expand Down
Expand Up @@ -16,7 +16,10 @@

package org.jbpm.process.audit;

import static org.jbpm.persistence.util.PersistenceUtil.*;
import static org.jbpm.persistence.util.PersistenceUtil.JBPM_PERSISTENCE_UNIT_NAME;
import static org.jbpm.persistence.util.PersistenceUtil.cleanUp;
import static org.jbpm.persistence.util.PersistenceUtil.createEnvironment;
import static org.jbpm.persistence.util.PersistenceUtil.setupWithPoolingDataSource;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

Expand Down
Expand Up @@ -16,7 +16,10 @@

package org.jbpm.process.audit;

import static org.jbpm.persistence.util.PersistenceUtil.*;
import static org.jbpm.persistence.util.PersistenceUtil.JBPM_PERSISTENCE_UNIT_NAME;
import static org.jbpm.persistence.util.PersistenceUtil.cleanUp;
import static org.jbpm.persistence.util.PersistenceUtil.createEnvironment;
import static org.jbpm.persistence.util.PersistenceUtil.setupWithPoolingDataSource;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

Expand Down
Expand Up @@ -15,7 +15,10 @@

package org.jbpm.process.audit;

import static org.jbpm.persistence.util.PersistenceUtil.*;
import static org.jbpm.persistence.util.PersistenceUtil.JBPM_PERSISTENCE_UNIT_NAME;
import static org.jbpm.persistence.util.PersistenceUtil.cleanUp;
import static org.jbpm.persistence.util.PersistenceUtil.createEnvironment;
import static org.jbpm.persistence.util.PersistenceUtil.setupWithPoolingDataSource;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

Expand Down
Expand Up @@ -19,13 +19,11 @@
import static org.jbpm.persistence.util.PersistenceUtil.createEnvironment;
import static org.jbpm.process.audit.AbstractAuditLogServiceTest.createKieSession;

import org.drools.core.impl.KnowledgeBaseImpl;
import org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler;
import org.kie.api.KieBase;
import org.kie.api.runtime.Environment;
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.process.ProcessInstance;
import org.kie.internal.KnowledgeBase;

/**
* This class tests the following classes:
Expand Down
Expand Up @@ -22,7 +22,6 @@
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import org.drools.core.impl.KnowledgeBaseImpl;
import org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler;
import org.junit.After;
import org.junit.Before;
Expand Down
Expand Up @@ -24,7 +24,6 @@
import javax.persistence.Persistence;

import org.drools.core.SessionConfiguration;
import org.drools.core.impl.KnowledgeBaseImpl;
import org.jbpm.process.audit.strategy.PersistenceStrategyType;
import org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler;
import org.junit.After;
Expand Down
Expand Up @@ -335,7 +335,7 @@ public void testDeleteProcessInstanceInfoLogByTimestamp() {
int p = 0;
Date endDate = pilTestData[p++].getEnd();

List<org.kie.api.runtime.manager.audit.ProcessInstanceLog> logs = this.processInstanceLogQuery().endDate(endDate).buildQuery().getResultList();
List<org.kie.api.runtime.manager.audit.ProcessInstanceLog> logs = this.processInstanceLogQuery().endDate(endDate).build().getResultList();
assertEquals(1, logs.size());

ProcessInstanceLogDeleteBuilder updateBuilder = this.processInstanceLogDelete().endDate(logs.get(0).getEnd());
Expand Down Expand Up @@ -427,7 +427,7 @@ public void testDeleteNodeInstanceInfoLogByTimestamp() {
int p = 0;
Date date = nilTestData[p++].getDate();

List<org.kie.api.runtime.manager.audit.NodeInstanceLog> logs = this.nodeInstanceLogQuery().date(date).buildQuery().getResultList();
List<org.kie.api.runtime.manager.audit.NodeInstanceLog> logs = this.nodeInstanceLogQuery().date(date).build().getResultList();
assertEquals(2, logs.size());


Expand Down Expand Up @@ -471,7 +471,7 @@ public void testDeleteVarInstanceInfoLogByTimestamp() {
int p = 0;
Date date = vilTestData[p++].getDate();

List<org.kie.api.runtime.manager.audit.VariableInstanceLog> vars = this.variableInstanceLogQuery().date(date).buildQuery().getResultList();
List<org.kie.api.runtime.manager.audit.VariableInstanceLog> vars = this.variableInstanceLogQuery().date(date).build().getResultList();
assertEquals(2, vars.size());

VariableInstanceLogDeleteBuilder updateBuilder = this.variableInstanceLogDelete().date(vars.get(0).getDate());
Expand Down
@@ -0,0 +1,127 @@
/*
* Copyright 2015 JBoss Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.jbpm.process.audit.query;

import static org.jbpm.persistence.util.PersistenceUtil.JBPM_PERSISTENCE_UNIT_NAME;
import static org.jbpm.process.audit.query.AuditQueryDataUtil.createTestNodeInstanceLogData;
import static org.jbpm.process.audit.query.AuditQueryDataUtil.createTestProcessInstanceLogData;
import static org.jbpm.process.audit.query.AuditQueryDataUtil.createTestVariableInstanceLogData;
import static org.jbpm.query.QueryBuilderCoverageTestUtil.afterClass;
import static org.jbpm.query.QueryBuilderCoverageTestUtil.beforeClass;
import static org.jbpm.query.QueryBuilderCoverageTestUtil.queryBuilderCoverageTest;

import javax.persistence.EntityManagerFactory;

import org.jbpm.persistence.correlation.JPACorrelationKeyFactory;
import org.jbpm.process.audit.JPAAuditLogService;
import org.jbpm.process.audit.NodeInstanceLog;
import org.jbpm.process.audit.ProcessInstanceLog;
import org.jbpm.process.audit.VariableInstanceLog;
import org.jbpm.process.audit.strategy.StandaloneJtaStrategy;
import org.jbpm.query.QueryBuilderCoverageTestUtil.ModuleSpecificInputFiller;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.kie.internal.process.CorrelationKey;
import org.kie.internal.runtime.manager.audit.query.AuditLogQueryBuilder.OrderBy;
import org.kie.internal.runtime.manager.audit.query.NodeInstanceLogQueryBuilder;
import org.kie.internal.runtime.manager.audit.query.ProcessInstanceLogQueryBuilder;
import org.kie.internal.runtime.manager.audit.query.VariableInstanceLogQueryBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AuditQueryCoverageTest extends JPAAuditLogService {

private static final Logger logger = LoggerFactory.getLogger(AuditQueryCoverageTest.class);

private static EntityManagerFactory emf;

private ProcessInstanceLog [] pilTestData;
private VariableInstanceLog [] vilTestData;
private NodeInstanceLog [] nilTestData;

@BeforeClass
public static void configure() {
emf = beforeClass(JBPM_PERSISTENCE_UNIT_NAME);
}

@AfterClass
public static void reset() {
afterClass();
}

@Before
public void setUp() throws Exception {
if( pilTestData == null ) {
// this is not really necessary..
pilTestData = createTestProcessInstanceLogData(emf);
vilTestData = createTestVariableInstanceLogData(emf);
nilTestData = createTestNodeInstanceLogData(emf);
}
this.persistenceStrategy = new StandaloneJtaStrategy(emf);
}

private static ModuleSpecificInputFiller inputFiller = new ModuleSpecificInputFiller() {

private final JPACorrelationKeyFactory correlationKeyFactory = new JPACorrelationKeyFactory();

private int orderByType = 0;

@Override
public Object fillInput( Class type ) {
if( type.equals(CorrelationKey.class) ) {
return correlationKeyFactory.newCorrelationKey("business-key");
} else if( type.equals(OrderBy.class) ) {
return ( orderByType++ % 2 == 0 ?
OrderBy.processId
: OrderBy.processInstanceId );
} else if( type.isArray() ) {
CorrelationKey [] corrKeyArr = {
correlationKeyFactory.newCorrelationKey("key:one"),
correlationKeyFactory.newCorrelationKey("key:two")
};
return corrKeyArr;
}
return null;
}
};

@Test
public void processInstanceLogQueryCoverageTest() {
ProcessInstanceLogQueryBuilder queryBuilder = this.processInstanceLogQuery();
Class builderClass = ProcessInstanceLogQueryBuilder.class;

queryBuilderCoverageTest(queryBuilder, builderClass, inputFiller);
}

@Test
public void variableInstanceLogQueryBuilderCoverageTest() {
VariableInstanceLogQueryBuilder queryBuilder = this.variableInstanceLogQuery();
Class builderClass = VariableInstanceLogQueryBuilder.class;

queryBuilderCoverageTest(queryBuilder, builderClass, inputFiller);
}

@Test
public void nodeInstanceLogQueryBuilderCoverageTest() {
NodeInstanceLogQueryBuilder queryBuilder = this.nodeInstanceLogQuery();
Class builderClass = NodeInstanceLogQueryBuilder.class;

queryBuilderCoverageTest(queryBuilder, builderClass, inputFiller);
}

}

0 comments on commit b919a69

Please sign in to comment.