From: Mathieu Baudier Date: Fri, 14 Aug 2015 16:04:34 +0000 (+0000) Subject: Refactor unit tests X-Git-Tag: argeo-commons-2.1.30~205 X-Git-Url: https://git.argeo.org/?a=commitdiff_plain;h=678d56847ac20b1e45e409d1b173266d285cbd4c;p=lgpl%2Fargeo-commons.git Refactor unit tests git-svn-id: https://svn.argeo.org/commons/trunk@8321 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/org.argeo.server.jcr/ext/test/org/argeo/jcr/AbstractInternalJackrabbitTestCase.java b/org.argeo.server.jcr/ext/test/org/argeo/jcr/AbstractInternalJackrabbitTestCase.java deleted file mode 100644 index 23281d075..000000000 --- a/org.argeo.server.jcr/ext/test/org/argeo/jcr/AbstractInternalJackrabbitTestCase.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2007-2012 Argeo GmbH - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * 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.argeo.jcr; - -import java.io.File; - -import javax.jcr.Repository; - -import org.apache.jackrabbit.core.TransientRepository; -import org.argeo.jcr.unit.AbstractJcrTestCase; -import org.springframework.core.io.ClassPathResource; -import org.springframework.core.io.Resource; - -/** Factorizes configuration of an in memory transient repository */ -public abstract class AbstractInternalJackrabbitTestCase extends - AbstractJcrTestCase { - protected File getRepositoryFile() throws Exception { - Resource res = new ClassPathResource( - "org/argeo/server/jcr/repository-memory.xml"); - return res.getFile(); - } - - protected Repository createRepository() throws Exception { - Repository repository = new TransientRepository(getRepositoryFile(), - getHomeDir()); - return repository; - } - -} diff --git a/org.argeo.server.jcr/ext/test/org/argeo/jcr/CollectionsObject.java b/org.argeo.server.jcr/ext/test/org/argeo/jcr/CollectionsObject.java deleted file mode 100644 index 1cbb931a7..000000000 --- a/org.argeo.server.jcr/ext/test/org/argeo/jcr/CollectionsObject.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (C) 2007-2012 Argeo GmbH - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * 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.argeo.jcr; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class CollectionsObject { - private String id; - private String label; - private SimpleObject simpleObject; - private List stringList = new ArrayList(); - private Map floatMap = new HashMap(); - private Map objectMap = new HashMap(); - private Map> mapOfMaps = new HashMap>(); - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getLabel() { - return label; - } - - public void setLabel(String label) { - this.label = label; - } - - public SimpleObject getSimpleObject() { - return simpleObject; - } - - public void setSimpleObject(SimpleObject simpleObject) { - this.simpleObject = simpleObject; - } - - public List getStringList() { - return stringList; - } - - public void setStringList(List stringList) { - this.stringList = stringList; - } - - public Map getFloatMap() { - return floatMap; - } - - public void setFloatMap(Map floatMap) { - this.floatMap = floatMap; - } - - public Map getObjectMap() { - return objectMap; - } - - public void setObjectMap(Map objectMap) { - this.objectMap = objectMap; - } - - public Map> getMapOfMaps() { - return mapOfMaps; - } - - public void setMapOfMaps(Map> mapOfMaps) { - this.mapOfMaps = mapOfMaps; - } -} diff --git a/org.argeo.server.jcr/ext/test/org/argeo/jcr/MapperTest.java b/org.argeo.server.jcr/ext/test/org/argeo/jcr/MapperTest.java deleted file mode 100644 index 8f4599cd6..000000000 --- a/org.argeo.server.jcr/ext/test/org/argeo/jcr/MapperTest.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) 2007-2012 Argeo GmbH - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * 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.argeo.jcr; - -import javax.jcr.Node; - -import org.argeo.jcr.spring.BeanNodeMapper; - -@Deprecated -public class MapperTest extends AbstractInternalJackrabbitTestCase { - public void testSimpleObject() throws Exception { - SimpleObject mySo = new SimpleObject(); - mySo.setInteger(100); - mySo.setString("hello world"); - - OtherObject oo1 = new OtherObject(); - oo1.setKey("someKey"); - oo1.setValue("stringValue"); - mySo.setOtherObject(oo1); - - OtherObject oo2 = new OtherObject(); - oo2.setKey("anotherSimpleObject"); - oo2.setValue(new SimpleObject()); - mySo.setAnotherObject(oo2); - - BeanNodeMapper bnm = new BeanNodeMapper(); - - Node node = bnm.save(session(), mySo); - session().save(); - JcrUtils.debug(node); - } -} diff --git a/org.argeo.server.jcr/ext/test/org/argeo/jcr/OtherObject.java b/org.argeo.server.jcr/ext/test/org/argeo/jcr/OtherObject.java deleted file mode 100644 index 5cce8ffaa..000000000 --- a/org.argeo.server.jcr/ext/test/org/argeo/jcr/OtherObject.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2007-2012 Argeo GmbH - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * 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.argeo.jcr; - -public class OtherObject { - private String key; - private Object value; - - public String getKey() { - return key; - } - - public void setKey(String key) { - this.key = key; - } - - public Object getValue() { - return value; - } - - public void setValue(Object value) { - this.value = value; - } -} diff --git a/org.argeo.server.jcr/ext/test/org/argeo/jcr/SimpleObject.java b/org.argeo.server.jcr/ext/test/org/argeo/jcr/SimpleObject.java deleted file mode 100644 index cdc32fc99..000000000 --- a/org.argeo.server.jcr/ext/test/org/argeo/jcr/SimpleObject.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) 2007-2012 Argeo GmbH - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * 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.argeo.jcr; - -import java.util.UUID; - -public class SimpleObject { - private String string; - private String uuid = UUID.randomUUID().toString(); - private Integer integer; - private OtherObject otherObject; - private OtherObject anotherObject; - - public String getString() { - return string; - } - - public void setString(String sting) { - this.string = sting; - } - - public Integer getInteger() { - return integer; - } - - public void setInteger(Integer integer) { - this.integer = integer; - } - - public OtherObject getOtherObject() { - return otherObject; - } - - public void setOtherObject(OtherObject otherObject) { - this.otherObject = otherObject; - } - - public OtherObject getAnotherObject() { - return anotherObject; - } - - public void setAnotherObject(OtherObject anotherObject) { - this.anotherObject = anotherObject; - } - - @Override - public boolean equals(Object obj) { - return string.equals(((SimpleObject) obj).string); - } - - @Override - public int hashCode() { - return string.hashCode(); - } - - public void setUuid(String uuid) { - this.uuid = uuid; - } - - public String getUuid() { - return uuid; - } - -} diff --git a/org.argeo.server.jcr/ext/test/org/argeo/jcr/spring/CollectionsObject.java b/org.argeo.server.jcr/ext/test/org/argeo/jcr/spring/CollectionsObject.java new file mode 100644 index 000000000..eadabfdad --- /dev/null +++ b/org.argeo.server.jcr/ext/test/org/argeo/jcr/spring/CollectionsObject.java @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2007-2012 Argeo GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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.argeo.jcr.spring; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class CollectionsObject { + private String id; + private String label; + private SimpleObject simpleObject; + private List stringList = new ArrayList(); + private Map floatMap = new HashMap(); + private Map objectMap = new HashMap(); + private Map> mapOfMaps = new HashMap>(); + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + public SimpleObject getSimpleObject() { + return simpleObject; + } + + public void setSimpleObject(SimpleObject simpleObject) { + this.simpleObject = simpleObject; + } + + public List getStringList() { + return stringList; + } + + public void setStringList(List stringList) { + this.stringList = stringList; + } + + public Map getFloatMap() { + return floatMap; + } + + public void setFloatMap(Map floatMap) { + this.floatMap = floatMap; + } + + public Map getObjectMap() { + return objectMap; + } + + public void setObjectMap(Map objectMap) { + this.objectMap = objectMap; + } + + public Map> getMapOfMaps() { + return mapOfMaps; + } + + public void setMapOfMaps(Map> mapOfMaps) { + this.mapOfMaps = mapOfMaps; + } +} diff --git a/org.argeo.server.jcr/ext/test/org/argeo/jcr/spring/MapperTest.java b/org.argeo.server.jcr/ext/test/org/argeo/jcr/spring/MapperTest.java new file mode 100644 index 000000000..e4bccd9ff --- /dev/null +++ b/org.argeo.server.jcr/ext/test/org/argeo/jcr/spring/MapperTest.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2007-2012 Argeo GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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.argeo.jcr.spring; + +import javax.jcr.Node; + +import org.argeo.jackrabbit.unit.AbstractJackrabbitTestCase; +import org.argeo.jcr.JcrUtils; +import org.argeo.jcr.spring.BeanNodeMapper; + +@Deprecated +public class MapperTest extends AbstractJackrabbitTestCase { + public void testSimpleObject() throws Exception { + SimpleObject mySo = new SimpleObject(); + mySo.setInteger(100); + mySo.setString("hello world"); + + OtherObject oo1 = new OtherObject(); + oo1.setKey("someKey"); + oo1.setValue("stringValue"); + mySo.setOtherObject(oo1); + + OtherObject oo2 = new OtherObject(); + oo2.setKey("anotherSimpleObject"); + oo2.setValue(new SimpleObject()); + mySo.setAnotherObject(oo2); + + BeanNodeMapper bnm = new BeanNodeMapper(); + + Node node = bnm.save(session(), mySo); + session().save(); + JcrUtils.debug(node); + } +} diff --git a/org.argeo.server.jcr/ext/test/org/argeo/jcr/spring/OtherObject.java b/org.argeo.server.jcr/ext/test/org/argeo/jcr/spring/OtherObject.java new file mode 100644 index 000000000..d6fb699b2 --- /dev/null +++ b/org.argeo.server.jcr/ext/test/org/argeo/jcr/spring/OtherObject.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2007-2012 Argeo GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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.argeo.jcr.spring; + +public class OtherObject { + private String key; + private Object value; + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public Object getValue() { + return value; + } + + public void setValue(Object value) { + this.value = value; + } +} diff --git a/org.argeo.server.jcr/ext/test/org/argeo/jcr/spring/SimpleObject.java b/org.argeo.server.jcr/ext/test/org/argeo/jcr/spring/SimpleObject.java new file mode 100644 index 000000000..d18dd04f6 --- /dev/null +++ b/org.argeo.server.jcr/ext/test/org/argeo/jcr/spring/SimpleObject.java @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2007-2012 Argeo GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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.argeo.jcr.spring; + +import java.util.UUID; + +public class SimpleObject { + private String string; + private String uuid = UUID.randomUUID().toString(); + private Integer integer; + private OtherObject otherObject; + private OtherObject anotherObject; + + public String getString() { + return string; + } + + public void setString(String sting) { + this.string = sting; + } + + public Integer getInteger() { + return integer; + } + + public void setInteger(Integer integer) { + this.integer = integer; + } + + public OtherObject getOtherObject() { + return otherObject; + } + + public void setOtherObject(OtherObject otherObject) { + this.otherObject = otherObject; + } + + public OtherObject getAnotherObject() { + return anotherObject; + } + + public void setAnotherObject(OtherObject anotherObject) { + this.anotherObject = anotherObject; + } + + @Override + public boolean equals(Object obj) { + return string.equals(((SimpleObject) obj).string); + } + + @Override + public int hashCode() { + return string.hashCode(); + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + public String getUuid() { + return uuid; + } + +} diff --git a/org.argeo.server.jcr/ext/test/org/argeo/jcr/tabular/JcrTabularTest.java b/org.argeo.server.jcr/ext/test/org/argeo/jcr/tabular/JcrTabularTest.java index 2045f9ae5..8896b2f4b 100644 --- a/org.argeo.server.jcr/ext/test/org/argeo/jcr/tabular/JcrTabularTest.java +++ b/org.argeo.server.jcr/ext/test/org/argeo/jcr/tabular/JcrTabularTest.java @@ -25,7 +25,7 @@ import javax.jcr.PropertyType; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.jackrabbit.commons.cnd.CndImporter; -import org.argeo.jcr.AbstractInternalJackrabbitTestCase; +import org.argeo.jackrabbit.unit.AbstractJackrabbitTestCase; import org.argeo.jcr.ArgeoNames; import org.argeo.jcr.ArgeoTypes; import org.argeo.util.tabular.TabularColumn; @@ -33,7 +33,7 @@ import org.argeo.util.tabular.TabularRow; import org.argeo.util.tabular.TabularRowIterator; import org.argeo.util.tabular.TabularWriter; -public class JcrTabularTest extends AbstractInternalJackrabbitTestCase { +public class JcrTabularTest extends AbstractJackrabbitTestCase { private final static Log log = LogFactory.getLog(JcrTabularTest.class); public void testWriteReadCsv() throws Exception { diff --git a/org.argeo.server.jcr/ext/test/org/argeo/server/jcr/JcrResourceAdapterTest.java b/org.argeo.server.jcr/ext/test/org/argeo/server/jcr/JcrResourceAdapterTest.java index b691572e9..3ce499af8 100644 --- a/org.argeo.server.jcr/ext/test/org/argeo/server/jcr/JcrResourceAdapterTest.java +++ b/org.argeo.server.jcr/ext/test/org/argeo/server/jcr/JcrResourceAdapterTest.java @@ -23,12 +23,12 @@ import java.util.List; import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.argeo.jcr.AbstractInternalJackrabbitTestCase; +import org.argeo.jackrabbit.unit.AbstractJackrabbitTestCase; import org.argeo.jcr.JcrResourceAdapter; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; -public class JcrResourceAdapterTest extends AbstractInternalJackrabbitTestCase { +public class JcrResourceAdapterTest extends AbstractJackrabbitTestCase { private static SimpleDateFormat sdf = new SimpleDateFormat( "yyyyMMdd:hhmmss.SSS"); diff --git a/org.argeo.server.jcr/src/org/argeo/jackrabbit/unit/AbstractJackrabbitTestCase.java b/org.argeo.server.jcr/src/org/argeo/jackrabbit/unit/AbstractJackrabbitTestCase.java new file mode 100644 index 000000000..1f3ff307a --- /dev/null +++ b/org.argeo.server.jcr/src/org/argeo/jackrabbit/unit/AbstractJackrabbitTestCase.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2007-2012 Argeo GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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.argeo.jackrabbit.unit; + +import java.io.File; + +import javax.jcr.Repository; + +import org.apache.jackrabbit.core.TransientRepository; +import org.argeo.jcr.unit.AbstractJcrTestCase; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; + +/** Factorizes configuration of an in memory transient repository */ +public abstract class AbstractJackrabbitTestCase extends + AbstractJcrTestCase { + protected File getRepositoryFile() throws Exception { + Resource res = new ClassPathResource( + "org/argeo/server/jcr/repository-memory.xml"); + return res.getFile(); + } + + protected Repository createRepository() throws Exception { + Repository repository = new TransientRepository(getRepositoryFile(), + getHomeDir()); + return repository; + } + +}