UISpec4J tests in Eclipse are not found - java

I am trying to run tests using the UISpec4J library, but Eclipse says it can not find them. I have tried restarting Eclipse, cleaning the project, etc.
The class gives no errors and I have followed the examples given on the website.
package com.health.gui;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.uispec4j.Button;
import org.uispec4j.Panel;
import org.uispec4j.UISpec4J;
import org.uispec4j.UISpecTestCase;
import org.uispec4j.Window;
import org.uispec4j.interception.WindowInterceptor;
import com.health.gui.input.xmlwizard.XmlFilePanel;
public class TestXmlFilePanel extends UISpecTestCase {
static {
UISpec4J.init();
}
private Panel panel;
#BeforeClass
public void setUp() {
panel = new Panel(new XmlFilePanel());
}
#Test
public void editWithoutSelectedTest() {
Button edit = panel.getButton("Edit selected");
Window popup = WindowInterceptor.run(edit.triggerClick());
popup.titleEquals("Warning!");
}
}
I get the following stacktrace:
junit.framework.AssertionFailedError: No tests found in com.health.gui.TestXmlFilePanel
at junit.framework.Assert.fail(Assert.java:57)
at junit.framework.TestCase.fail(TestCase.java:227)
at junit.framework.TestSuite$1.runTest(TestSuite.java:100)
at junit.framework.TestCase.runBare(TestCase.java:141)
at junit.framework.TestResult$1.protect(TestResult.java:122)
at junit.framework.TestResult.runProtected(TestResult.java:142)
at junit.framework.TestResult.run(TestResult.java:125)
at junit.framework.TestCase.run(TestCase.java:129)
at junit.framework.TestSuite.runTest(TestSuite.java:255)
at junit.framework.TestSuite.run(TestSuite.java:250)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:84)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
I really have no clue what is wrong. Maybe you have some suggestions?

just for fun. you can remove "extends UISpecTestCase" in your class and give it a try see if it works or not :)
Junit 4.X should support annotation well and I didn't see any reason you need to extends UISpecTestCase.

Related

java.lang.IllegalStateException: Missing the '-javaagent' JVM argument. Make sure you run the tests with the Quasar java agent attached to your JVM

When trying to run test for CORDA the given Test case getting the following error. I am using JDK 1.8., Intellij IDEA on Windows 10. Even Though I have mentioned the the Quasar.jar in VM options.
RUN >> Edit Configurations >> Junit>> Required Test Class >>VM options:-ea -javaagent:lib\quasar.jar
enter image description here
package com.template;
import com.google.common.collect.ImmutableList;
import com.template.contracts.MetalContract;
import com.template.flows.Responder;
import com.template.states.MetalState;
import net.corda.core.concurrent.CordaFuture;
import net.corda.core.contracts.Command;
import net.corda.core.contracts.TransactionState;
import net.corda.core.transactions.SignedTransaction;
import net.corda.testing.node.MockNetwork;
import net.corda.testing.node.MockNetworkParameters;
import net.corda.testing.node.StartedMockNode;
import net.corda.testing.node.TestCordapp;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.template.flows.IssueMetal;
import com.template.flows.TransferMetal;
import static org.junit.Assert.assertEquals;
import static junit.framework.TestCase.assertTrue;
public class FlowTests {
private final MockNetwork network = new MockNetwork(new MockNetworkParameters(ImmutableList.of(
TestCordapp.findCordapp("com.template.contracts"),
TestCordapp.findCordapp("com.template.flows")
)));
private final StartedMockNode Mint = network.createNode();
private final StartedMockNode A = network.createNode();
private final StartedMockNode B = network.createNode();
#Before
public void setup() {
network.runNetwork();
}
#After
public void tearDown() {
network.stopNodes();
}
// ------------------------------------------ Issue Metal Flow Tests ----------------------------------------
#Test
public void transactionHasNoInputsHasOneMetalStateOutputWithTheCorrectOwner() throws Exception {
IssueMetal flow = new IssueMetal("Gold", 10, A.getInfo().getLegalIdentities().get(0));
CordaFuture<SignedTransaction> future = Mint.startFlow(flow);
setup();
SignedTransaction signedTransaction = future.get();
assertEquals (0, signedTransaction.getTx().getInputs().size());
assertEquals (1, signedTransaction.getTx().getOutputStates().size());
MetalState output = signedTransaction.getTx().outputsOfType(MetalState.class).get(0);
assertEquals(A.getInfo().getLegalIdentities().get(0), output.getOwner());
}
}
The Error is :
java.lang.IllegalStateException: Missing the '-javaagent' JVM argument. Make sure you run the tests with the Quasar java agent attached to your JVM.
See https://docs.corda.net/head/testing.html#running-tests-in-intellij - 'Fiber classes not instrumented' for more details.
at net.corda.node.services.statemachine.SingleThreadedStateMachineManager.checkQuasarJavaAgentPresence(SingleThreadedStateMachineManager.kt:317)
at net.corda.node.services.statemachine.SingleThreadedStateMachineManager.start(SingleThreadedStateMachineManager.kt:135)
at net.corda.node.internal.AbstractNode$start$8.invoke(AbstractNode.kt:409)
at net.corda.node.internal.AbstractNode$start$8.invoke(AbstractNode.kt:122)
at net.corda.nodeapi.internal.persistence.CordaPersistence.inTopLevelTransaction(CordaPersistence.kt:268)
at net.corda.nodeapi.internal.persistence.CordaPersistence.transaction(CordaPersistence.kt:237)
at net.corda.nodeapi.internal.persistence.CordaPersistence.transaction(CordaPersistence.kt:254)
at net.corda.node.internal.AbstractNode.start(AbstractNode.kt:388)
at net.corda.testing.node.internal.InternalMockNetwork$MockNode.start(InternalMockNetwork.kt:346)
at net.corda.testing.node.internal.InternalMockNetwork.createNodeImpl(InternalMockNetwork.kt:471)
at net.corda.testing.node.internal.InternalMockNetwork.createNode(InternalMockNetwork.kt:449)
at net.corda.testing.node.internal.InternalMockNetwork.createNode(InternalMockNetwork.kt:444)
at net.corda.testing.node.internal.InternalMockNetwork.createNotaries$node_driver(InternalMockNetwork.kt:253)
at net.corda.testing.node.internal.InternalMockNetwork.<init>(InternalMockNetwork.kt:236)
at net.corda.testing.node.internal.InternalMockNetwork.<init>(InternalMockNetwork.kt:149)
at net.corda.testing.node.MockNetwork.<init>(MockNetwork.kt:305)
at net.corda.testing.node.MockNetwork.<init>(MockNetwork.kt:294)
at net.corda.testing.node.MockNetwork.<init>(MockNetwork.kt:303)
at com.template.FlowTests.<init>(FlowTests.java:25)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:217)
at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:266)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:64)
I would recommend using the Gradle Test Runner so that you don't have to set the javaagent flag manually.
To use Gradle Test Runner Click the Run/Debug configuration drop down > Edit Configurations... > + > Gradle In the form that appears, fill in the details:
Gradle-Project : [path to your project]
Task: :cleanTest :test
Arguments: --tests ""
Reference below:

java.lang.AssertionError: Cassandra daemon did not start within timeout

My Test Class :
public class NetworkSettingsDaoTest {
#Rule
public CassandraCQLUnit cassandraCQLUnit = new CassandraCQLUnit(new ClassPathCQLDataSet("simpleWithCreateKeyspace.cql"));
public static Session session;
public static NetworkSettingsDao networkSettingsDao;
#Before
public void init() throws ConfigurationException, TTransportException, IOException, InterruptedException{
EmbeddedCassandraServerHelper.startEmbeddedCassandra(5600000L);
//Thread.sleep(4*1000); //workaround for weak machine
session = cassandraCQLUnit.getSession();
networkSettingsDao = new NetworkSettingsDao();
}
#Test
public void should_have_started_and_execute_cql_script() throws Exception {
ResultSet result = session.execute("select * from mytable WHERE id='myKey01'");
assertThat(result.iterator().next().getString("value"), is("myValue01"));
}
}
My simpleWithCreateKeyspace.cql file :
CREATE KEYSPACE NETWORKSETTINGS WITH replication={'class' : 'SimpleStrategy', 'replication_factor':1};
USE NETWORKSETTINGS;
CREATE TABLE STBDevice(
KEY varchar,
SETTINGS_COLUMN varchar,
AMSIP varchar,
PRIMARY KEY(KEY));
INSERT INTO STBDevice(KEY, SETTINGS_COLUMN,AMSIP) values('myKey01','myColumn1','myAMSIP1');
Exception :
java.lang.AssertionError: Cassandra daemon did not start within
timeout at
org.cassandraunit.utils.EmbeddedCassandraServerHelper.startEmbeddedCassandra(EmbeddedCassandraServerHelper.java:130)
at
org.cassandraunit.utils.EmbeddedCassandraServerHelper.startEmbeddedCassandra(EmbeddedCassandraServerHelper.java:85)
at
org.cassandraunit.utils.EmbeddedCassandraServerHelper.startEmbeddedCassandra(EmbeddedCassandraServerHelper.java:64)
at
org.cassandraunit.utils.EmbeddedCassandraServerHelper.startEmbeddedCassandra(EmbeddedCassandraServerHelper.java:56)
at
org.cassandraunit.BaseCassandraUnit.before(BaseCassandraUnit.java:28)
at
org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:46)
at org.junit.rules.RunRules.evaluate(RunRules.java:20) at
org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at
org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at
org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at
org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at
org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at
org.junit.runners.ParentRunner.run(ParentRunner.java:309) at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
In my case, the server ALWAYS started within the default 10 sec window until yesterday. Today, it takes 50 to 70 secs. No valid explanation. So, looks like the only option is to increase the timeout.
Looks, It depends on the number of queries you fire on Cassandra.. If you have too many queries to run then you need to increase the timeout in EmbeddedCassandra annotation. #EmbeddedCassandra(timeout = 100000L)
This class helped to solve problems
package org.cassandraunit.test.spring.cql;
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Session;
import org.cassandraunit.spring.CassandraDataSet;
import org.cassandraunit.spring.CassandraUnitTestExecutionListener;
import org.cassandraunit.spring.EmbeddedCassandra;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
#RunWith(SpringJUnit4ClassRunner.class)
#TestExecutionListeners({ CassandraUnitTestExecutionListener.class })
#CassandraDataSet(value = { "simple.cql" })
#EmbeddedCassandra
public class SpringCQLScriptLoadTest {
#Test
public void should_have_started_and_execute_cql_script() throws Exception {
Cluster cluster = Cluster.builder()
.addContactPoints("127.0.0.1")
.withPort(9142)
.build();
Session session = cluster.connect("cassandra_unit_keyspace");
ResultSet result = session.execute("select * from mytable WHERE id='myKey01'");
assertThat(result.iterator().next().getString("value"), is("myValue01"));
}
}

Junit Testing with SpringFramework, without Maven : Error - NoSuchMethodError

I'm new with JUnit - Spring Framework.
What I'm doing is, creating some Tests for my Application. Here is Code what I have did.
#RunWith(SpringJUnit4ClassRunner.class)
public class InspirdTests {
#Autowired
private PlatformBLL platform;
#Autowired
private WebApplicationContext webAppContext;
#Before
public void settingUp(){
System.out.println("Before SetUp");
}
#Test
public void setUp() throws Exception{
System.out.println("Before : " + platform);
platform.getAllProjectsForPlatform(null);
System.out.println("After : " + platform);
}
}
and the Stack Trace
java.lang.NoSuchMethodError: org.junit.runner.notification.RunNotifier.testAborted(Lorg/junit/runner/Description;Ljava/lang/Throwable;)V
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:155)
at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:61)
at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:54)
at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:33)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:45)
at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:52)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:97)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
I'm just blocked, Im stucked with it, i just cant move ahead.
What I have tried:
A lot google, but the result is as it is.
I had made some blank Methods for Testing, Still Result is as it is.
I have added JUnit-4.12.jar into WEB-INF/lib/
I have added Junit 4 into Java Build Path
Guys please Help me to Find out Solution for it.
Include spring-test and junit jars in your eclipse buildpath.
import org.junit.After;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;
#ContextConfiguration(locations = { "classpath:/conf/applicationContext.xml"})
#RunWith(SpringJUnit4ClassRunner.class)
public class MongoRepositoryImplTest {
#Autowired
MongoRepositoryImpl mongoRepositoryImpl;
#Test
public void testGetMongoConnectionFromFactory() {
...
}
...
Config file should look like:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd">
<context:component-scan base-package="com.client.impl" />
<bean id="mongoRepositoryImpl" class="com.client.impl.MongoRepositoryImpl">
<constructor-arg name="connectionName" value="testCases"/>
</bean>
</beans>

#Rule declaration causes error on a debug attempt

A groovy JUnit test class has only one static declaration:
#Rule
public static ErrorCollector errorCollector;
After an attempt to launch the test in debug mode an exception raises:
java.lang.NullPointerException
at org.junit.runners.BlockJUnit4ClassRunner.withRules(BlockJUnit4ClassRunner.java:354)
at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:270)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
The exception raises before any line in the code is started.
If I throw away the "#Rule" word, the test is running OK (at least from the start)
Imports are:
import static org.hamcrest.CoreMatchers.*;
import org.hamcrest.Matcher;
import static org.hamcrest.Matchers.*;
import org.junit.Rule;
import org.junit.rules.ErrorCollector;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.Before;
import groovy.util.slurpersupport.NodeChild
import groovy.xml.MarkupBuilder
import groovy.xml.StreamingMarkupBuilder
import groovy.xml.XmlUtil
import org.codehaus.groovy.tools.xml.DomToGroovy
import org.joda.time.DateTime
import org.w3c.dom.Document;
import java.util.concurrent.Callable;
JUnit version 4.8.2
Eclipse version: 3.6
Java version: 1.6.41
Where should I look for problems, please?
As you can see at ErrorCollector javadoc, you must create a instance to use it, like this:
#Rule
public ErrorCollector collector= new ErrorCollector();
It seems as a bug in Runner:
//Correct variants:
#Rule
public ErrorCollector collector1= new ErrorCollector();
public ErrorCollector collector2= null;
#Rule
collector2= new ErrorCollector();
public ErrorCollector collector3;
#Rule
collector3= new ErrorCollector();
// incorrect variants:
#Rule
public ErrorCollector collector4= null;
#Rule
public ErrorCollector collector5;
#Rule
public ErrorCollector collector5=somethingThatIsNotRule;
#Rule
public ErrorCollector collector5=anotherRule;
//BUT:
//the runner takes the following, and runs it without problems, too:
public ErrorCollector collector6= null;
{
#Rule
collector6= null;
}
So, the runner makes an excessive check before constructing the test.

Spring ROO: JUnit test fails

I am having trouble executing my Spring IntegrationTests, when i run the code below it is failing at the persist method:
#RooIntegrationTest(entity = Person.class)
public class PersonIntegrationTest {
#Test
public void test() {
}
#Test
public void testCountPeople(){
Person personToPersist = PersonTestUtil.createTestPerson();
personToPersist.persist();
Long count = Person.countPeople();
assertNotNull(personToPersist);
assertTrue(personToPersist.countPeople() == 1);
}
}
The Stack trace is below
java.lang.IllegalStateException: Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)
at org.bixin.dugsi.domain.Person_Roo_Entity.ajc$interMethod$org_bixin_dugsi_domain_Person_Roo_Entity$org_bixin_dugsi_domain_Person$entityManager(Person_Roo_Entity.aj:95)
at org.bixin.dugsi.domain.Person.entityManager(Person.java:1)
at org.bixin.dugsi.domain.Person_Roo_Entity.ajc$interMethodDispatch1$org_bixin_dugsi_domain_Person_Roo_Entity$org_bixin_dugsi_domain_Person$entityManager(Person_Roo_Entity.aj)
at org.bixin.dugsi.domain.Person_Roo_Entity.ajc$interMethod$org_bixin_dugsi_domain_Person_Roo_Entity$org_bixin_dugsi_domain_Person$persist(Person_Roo_Entity.aj:58)
at org.bixin.dugsi.domain.Person.persist(Person.java:1)
at org.bixin.dugsi.domain.Person_Roo_Entity.ajc$interMethodDispatch1$org_bixin_dugsi_domain_Person_Roo_Entity$org_bixin_dugsi_domain_Person$persist(Person_Roo_Entity.aj)
at org.bixin.dugsi.domain.PersonIntegrationTest.testCountPeople(PersonIntegrationTest.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Anyone run into this problem?
It seems that you have not injected the EntityManager and the related application context to your test.
Please try adding the following line above the class declaration.
#ContextConfiguration(locations = { "/META-INF/spring/applicationContext.xml","/META-INF/spring/applicationContext-security.xml" })
and try making your test class to inhert from AbstractJUnit4SpringContextTests. Do keep in mind that you might have to implement authentication for some operations to be executed.
Your test class could look like below.
package com.myapp.test;
#ContextConfiguration(locations = { "/META-INF/spring/applicationContext.xml","/META-INF/spring/applicationContext-security.xml" })
public class TestMyService extends AbstractJUnit4SpringContextTests {
#Autowired
MyService service = new MyService();
private void setUp() {
//Do the setting up of your classes for the test
}
#Test
public void testOperation() throws IOException {
//My Test Code here
}
}
Note that you should generally have a different context for your testing purposes.
Cheers.
If you're using Springsource Tool Suite (or another Eclipse) try to clean the project. I think Eclipse someimes doesn't use the AJDT Compiler, specially at startup.
I don't remember this message from the Roo console, that uses maven under the hood.
Try "perform eclipse" from the Roo shell or even maven directly from the console (mvn clean install or something like that)
It seems that you forgot to inject the EntityManager and the application context.
Try something like this, it worked for me with Spring Roo:
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import com.jitter.finance.analyzer.domain.Address;
#ContextConfiguration(locations = { "classpath*:/META-INF/spring/applicationContext*.xml"})
public class EmTest extends AbstractJUnit4SpringContextTests {
#Test
public void checkEm(){
Address a = new Address();
a.setName("Primo");
a.persist();
Address b = new Address();
b.setName("Secondo");
b.persist();
for(Address ad : Address.findAllAddresses()){
System.out.println(ad.getName());
assertEquals(ad.getName().charAt(ad.getName().length()-1), 'o');
}
}
}

Categories

Resources