JUnit with RepositoryTestCase

Hi,

could please explain where can I find some documentation about org.onehippo.repository.testutils.RepositoryTestCase?

I would like to Test HippoCMS Classes, my own Validators, Services and Repository.
Unfortunately I get following Error

javax.jcr.RepositoryException: unchecked exception: java.lang.IllegalStateException: Node ‘/hippo:configuration/hippo:translations/hippo:cms/validators/de’ defined at ‘Hippo-CMS/Hippo-CMS/Hippo-CMS-repository-data-application [config: configuration/translations/cms.yaml]’ is missing the required jcr:primaryType property.

cms.yaml . seems to be OK (is working in the produtction mode now) :

------cms.yaml------
definitions:
config:
/hippo:configuration/hippo:translations/hippo:cms/validators/en:
seo-fields#title-too-long: Title limited to 70 characters
seo-fields#description-too-long: Description limited to 160 characters
seo-fields#keywords-too-long: The keywords limited to 5 terms
seo-fields#canonical-not-absolute: The canonical URL has to be absolute
link-compound#link-and-downloadlink-set: Link and download link cannot be set
at the same time
link-compound#internal-link-absolute: Internal links should not be absolute
/hippo:configuration/hippo:translations/hippo:cms/validators/de:
seo-fields#description-too-long: Description ist beschränkt auf 160 Zeichen
seo-fields#canonical-not-absolute: Canonical URL muss absolut sein
seo-fields#keywords-too-long: Keywords ist beschränkt auf 5 Begriffe
seo-fields#title-too-long: Title ist beschränkt auf 70 Zeichen
link-compound#internal-link-absolute: Interne Links sollten nicht absolut sein
link-compound#link-and-downloadlink-set: Link und Donwload Link können nicht
zu gleichen Zeit gesetzt sein


<dependency>
  <groupId>org.onehippo.cms7.hst</groupId>
  <artifactId>hst-test</artifactId>
  <version>5.3.0</version>
  <scope>test</scope>
</dependency>

Now I edited cms.yaml …
definitions:
config:
/hippo:configuration/hippo:translations/hippo:cms/validators/en:
_**jcr:primaryType: hipposys:resourcebundle**_
seo-fields#title-too-long: Title limited to 70 characters

New Error :

javax.jcr.RepositoryException: unchecked exception: java.lang.NoClassDefFoundError: com/onehippo/cms7/services/hst/WorkspaceHasher

at org.hippoecm.repository.HippoRepositoryFactory.getHippoRepository(HippoRepositoryFactory.java:161)
at org.onehippo.repository.testutils.RepositoryTestCase.setUpClass(RepositoryTestCase.java:115)
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 org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
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.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

Caused by: java.lang.NoClassDefFoundError: com/onehippo/cms7/services/hst/WorkspaceHasher
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at org.onehippo.cm.engine.ConfigurationServiceImpl.loadMigrators(ConfigurationServiceImpl.java:733)

hippo-enterprise-services-1.3.0.jar is loaded

I think you don’t have all your dependencies defined correctly. You may need some extra dependencies for the test classes. Best to compare with other modules that use the RepositoryTestCase.

Unfortunately there is not really documentation on the RepositoryTestCase.

10x. Could you give me some Ideas how can I run JUnits, testing Hippo Plugins, Services, , or other stuff?

Example issue : I want to Test org.hippoecm.frontend.plugins.console.menu.save.SaveDialog.
I found out how can I listen for Events, but I have a big problem to call onOk from SaveDialog.

I tried following :

HippoServiceRegistry.registerService(eventBus = new GuavaHippoEventBus(), HippoEventBus.class);
HippoServiceRegistry.registerService(listenerEvents = new ListenerHippoEvent(), HippoEventBus.class);
HippoEvent event = new HippoEvent(“console”);
event.category(“console”).user(“max”).action(“test”);
event.message(“hello world”);
eventBus.post(event);
waitForEvent(listenerEvents);

private void waitForEvent(final ListenerHippoEvent listener) throws Exception {
int n = 50;
System.out.println(" Start waiting for HippoEvent …");
while (n-- > 0) {
Thread.sleep(100);
if (listener.seenEvents.size() == 1) {
Thread.sleep(100);
return;
}
}
throw new Exception(“HippoEvent not received within 5 seconds”);
}

public static class ListenerHippoEvent {
	List<HippoEvent> seenEvents = new LinkedList<HippoEvent>();
	@Subscribe
	public void handleEvent(HippoEvent event) {
		System.out.println("  received HippoEvent message: " + event.message());
		seenEvents.add(event);
	}
}

So I just can send and receive Events by myself… But I want Events from SaveDialog

Could somebody help?

I think this gets into testing Wicket. You aren’t waiting for a repository event but for a UI event. I’m not sure how that would be done in a unit test.