cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From skolbac...@apache.org
Subject cayenne git commit: CAY-1999 | Add some unit tests
Date Wed, 29 Apr 2015 13:47:47 GMT
Repository: cayenne
Updated Branches:
  refs/heads/master 412cf30f2 -> 7ca6164bb


CAY-1999 | Add some unit tests


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/7ca6164b
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/7ca6164b
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/7ca6164b

Branch: refs/heads/master
Commit: 7ca6164bb6553435d676cf4fcb1a54184e54fd78
Parents: 412cf30
Author: Savva Kolbachev <s.kolbachev@gmail.com>
Authored: Wed Apr 29 16:47:04 2015 +0300
Committer: Savva Kolbachev <s.kolbachev@gmail.com>
Committed: Wed Apr 29 16:47:04 2015 +0300

----------------------------------------------------------------------
 .../apache/cayenne/gen/ClassGenerationCase.java | 59 ++++++++++++++
 .../gen/ClientSuperClassGenerationTest.java     | 86 ++++++++++++++++++++
 .../cayenne/gen/SingleClassGenerationTest.java  | 86 ++++++++++++++++++++
 .../cayenne/gen/SuperClassGenerationTest.java   | 86 ++++++++++++++++++++
 4 files changed, 317 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/7ca6164b/cayenne-tools/src/test/java/org/apache/cayenne/gen/ClassGenerationCase.java
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/test/java/org/apache/cayenne/gen/ClassGenerationCase.java b/cayenne-tools/src/test/java/org/apache/cayenne/gen/ClassGenerationCase.java
new file mode 100644
index 0000000..44b709d
--- /dev/null
+++ b/cayenne-tools/src/test/java/org/apache/cayenne/gen/ClassGenerationCase.java
@@ -0,0 +1,59 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.cayenne.gen;
+
+import org.apache.velocity.Template;
+import org.apache.velocity.app.VelocityEngine;
+import org.apache.velocity.context.Context;
+import org.apache.velocity.runtime.RuntimeConstants;
+import org.apache.velocity.runtime.log.NullLogSystem;
+import org.junit.Before;
+
+import java.io.StringWriter;
+import java.util.Properties;
+
+public class ClassGenerationCase {
+
+    private VelocityEngine velocityEngine;
+
+    @Before
+    public void setUp() throws Exception {
+        Properties props = new Properties();
+
+        // null logger that will prevent velocity.log from being generated
+        props.put(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, NullLogSystem.class.getName());
+        props.put("resource.loader", "cayenne");
+        props.put("cayenne.resource.loader.class", ClassGeneratorResourceLoader.class.getName());
+        props.put("cayenne.resource.loader.cache", "false");
+
+        this.velocityEngine = new VelocityEngine();
+        this.velocityEngine.init(props);
+    }
+
+    protected String renderTemplate(String templateName, Context context) throws Exception
{
+        StringWriter writer = new StringWriter();
+
+        Template template = velocityEngine.getTemplate(templateName);
+        template.merge(context, writer);
+
+        return writer.toString();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/7ca6164b/cayenne-tools/src/test/java/org/apache/cayenne/gen/ClientSuperClassGenerationTest.java
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/test/java/org/apache/cayenne/gen/ClientSuperClassGenerationTest.java
b/cayenne-tools/src/test/java/org/apache/cayenne/gen/ClientSuperClassGenerationTest.java
new file mode 100644
index 0000000..b690367
--- /dev/null
+++ b/cayenne-tools/src/test/java/org/apache/cayenne/gen/ClientSuperClassGenerationTest.java
@@ -0,0 +1,86 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.cayenne.gen;
+
+import org.apache.cayenne.map.ObjAttribute;
+import org.apache.cayenne.map.ObjEntity;
+import org.apache.cayenne.map.ObjRelationship;
+import org.apache.velocity.VelocityContext;
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class ClientSuperClassGenerationTest extends ClassGenerationCase {
+
+    @Test
+    public void testNotContainsPropertyImport() throws Exception {
+        ObjEntity objEntity = new ObjEntity("TEST1");
+
+        VelocityContext context = new VelocityContext();
+        context.put(Artifact.OBJECT_KEY, objEntity);
+
+        String res = renderTemplate(ClientClassGenerationAction.SUPERCLASS_TEMPLATE, context);
+        assertFalse(res.contains("org.apache.cayenne.exp.Property"));
+    }
+
+    @Test
+    public void testContainsPropertyImportForAttributes() throws Exception {
+        ObjEntity objEntity = new ObjEntity("TEST1");
+        ObjAttribute attr = new ObjAttribute("attr");
+        objEntity.addAttribute(attr);
+
+        VelocityContext context = new VelocityContext();
+        context.put(Artifact.OBJECT_KEY, objEntity);
+
+        String res = renderTemplate(ClientClassGenerationAction.SUPERCLASS_TEMPLATE, context);
+        assertTrue(res.contains("org.apache.cayenne.exp.Property"));
+    }
+
+    @Test
+    public void testContainsPropertyImportForRelationships() throws Exception {
+        ObjEntity objEntity = new ObjEntity("TEST1");
+        ObjRelationship rel = new ObjRelationship("rel");
+        objEntity.addRelationship(rel);
+
+        VelocityContext context = new VelocityContext();
+        context.put(Artifact.OBJECT_KEY, objEntity);
+
+        String res = renderTemplate(ClientClassGenerationAction.SUPERCLASS_TEMPLATE, context);
+        assertTrue(res.contains("org.apache.cayenne.exp.Property"));
+    }
+
+    @Test
+    public void testContainsPropertyImport() throws Exception {
+        ObjEntity objEntity = new ObjEntity("TEST1");
+        ObjAttribute attr = new ObjAttribute("attr");
+        ObjRelationship rel = new ObjRelationship("rel");
+
+        objEntity.addAttribute(attr);
+        objEntity.addRelationship(rel);
+
+        VelocityContext context = new VelocityContext();
+        context.put(Artifact.OBJECT_KEY, objEntity);
+
+        String res = renderTemplate(ClientClassGenerationAction.SUPERCLASS_TEMPLATE, context);
+        assertTrue(res.contains("org.apache.cayenne.exp.Property"));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/7ca6164b/cayenne-tools/src/test/java/org/apache/cayenne/gen/SingleClassGenerationTest.java
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/test/java/org/apache/cayenne/gen/SingleClassGenerationTest.java
b/cayenne-tools/src/test/java/org/apache/cayenne/gen/SingleClassGenerationTest.java
new file mode 100644
index 0000000..0bbe9e9
--- /dev/null
+++ b/cayenne-tools/src/test/java/org/apache/cayenne/gen/SingleClassGenerationTest.java
@@ -0,0 +1,86 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.cayenne.gen;
+
+import org.apache.cayenne.map.ObjAttribute;
+import org.apache.cayenne.map.ObjEntity;
+import org.apache.cayenne.map.ObjRelationship;
+import org.apache.velocity.VelocityContext;
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class SingleClassGenerationTest extends ClassGenerationCase {
+
+    @Test
+    public void testNotContainsPropertyImport() throws Exception {
+        ObjEntity objEntity = new ObjEntity("TEST1");
+
+        VelocityContext context = new VelocityContext();
+        context.put(Artifact.OBJECT_KEY, objEntity);
+
+        String res = renderTemplate(ClassGenerationAction.SINGLE_CLASS_TEMPLATE, context);
+        assertFalse(res.contains("org.apache.cayenne.exp.Property"));
+    }
+
+    @Test
+    public void testContainsPropertyImportForAttributes() throws Exception {
+        ObjEntity objEntity = new ObjEntity("TEST1");
+        ObjAttribute attr = new ObjAttribute("attr");
+        objEntity.addAttribute(attr);
+
+        VelocityContext context = new VelocityContext();
+        context.put(Artifact.OBJECT_KEY, objEntity);
+
+        String res = renderTemplate(ClassGenerationAction.SINGLE_CLASS_TEMPLATE, context);
+        assertTrue(res.contains("org.apache.cayenne.exp.Property"));
+    }
+
+    @Test
+    public void testContainsPropertyImportForRelationships() throws Exception {
+        ObjEntity objEntity = new ObjEntity("TEST1");
+        ObjRelationship rel = new ObjRelationship("rel");
+        objEntity.addRelationship(rel);
+
+        VelocityContext context = new VelocityContext();
+        context.put(Artifact.OBJECT_KEY, objEntity);
+
+        String res = renderTemplate(ClassGenerationAction.SINGLE_CLASS_TEMPLATE, context);
+        assertTrue(res.contains("org.apache.cayenne.exp.Property"));
+    }
+
+    @Test
+    public void testContainsPropertyImport() throws Exception {
+        ObjEntity objEntity = new ObjEntity("TEST1");
+        ObjAttribute attr = new ObjAttribute("attr");
+        ObjRelationship rel = new ObjRelationship("rel");
+
+        objEntity.addAttribute(attr);
+        objEntity.addRelationship(rel);
+
+        VelocityContext context = new VelocityContext();
+        context.put(Artifact.OBJECT_KEY, objEntity);
+
+        String res = renderTemplate(ClassGenerationAction.SINGLE_CLASS_TEMPLATE, context);
+        assertTrue(res.contains("org.apache.cayenne.exp.Property"));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/7ca6164b/cayenne-tools/src/test/java/org/apache/cayenne/gen/SuperClassGenerationTest.java
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/test/java/org/apache/cayenne/gen/SuperClassGenerationTest.java
b/cayenne-tools/src/test/java/org/apache/cayenne/gen/SuperClassGenerationTest.java
new file mode 100644
index 0000000..0a47d63
--- /dev/null
+++ b/cayenne-tools/src/test/java/org/apache/cayenne/gen/SuperClassGenerationTest.java
@@ -0,0 +1,86 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.cayenne.gen;
+
+import org.apache.cayenne.map.ObjAttribute;
+import org.apache.cayenne.map.ObjEntity;
+import org.apache.cayenne.map.ObjRelationship;
+import org.apache.velocity.VelocityContext;
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class SuperClassGenerationTest extends ClassGenerationCase {
+
+    @Test
+    public void testNotContainsPropertyImport() throws Exception {
+        ObjEntity objEntity = new ObjEntity("TEST1");
+
+        VelocityContext context = new VelocityContext();
+        context.put(Artifact.OBJECT_KEY, objEntity);
+
+        String res = renderTemplate(ClassGenerationAction.SUPERCLASS_TEMPLATE, context);
+        assertFalse(res.contains("org.apache.cayenne.exp.Property"));
+    }
+
+    @Test
+    public void testContainsPropertyImportForAttributes() throws Exception {
+        ObjEntity objEntity = new ObjEntity("TEST1");
+        ObjAttribute attr = new ObjAttribute("attr");
+        objEntity.addAttribute(attr);
+
+        VelocityContext context = new VelocityContext();
+        context.put(Artifact.OBJECT_KEY, objEntity);
+
+        String res = renderTemplate(ClassGenerationAction.SUPERCLASS_TEMPLATE, context);
+        assertTrue(res.contains("org.apache.cayenne.exp.Property"));
+    }
+
+    @Test
+    public void testContainsPropertyImportForRelationships() throws Exception {
+        ObjEntity objEntity = new ObjEntity("TEST1");
+        ObjRelationship rel = new ObjRelationship("rel");
+        objEntity.addRelationship(rel);
+
+        VelocityContext context = new VelocityContext();
+        context.put(Artifact.OBJECT_KEY, objEntity);
+
+        String res = renderTemplate(ClassGenerationAction.SUPERCLASS_TEMPLATE, context);
+        assertTrue(res.contains("org.apache.cayenne.exp.Property"));
+    }
+
+    @Test
+    public void testContainsPropertyImport() throws Exception {
+        ObjEntity objEntity = new ObjEntity("TEST1");
+        ObjAttribute attr = new ObjAttribute("attr");
+        ObjRelationship rel = new ObjRelationship("rel");
+
+        objEntity.addAttribute(attr);
+        objEntity.addRelationship(rel);
+
+        VelocityContext context = new VelocityContext();
+        context.put(Artifact.OBJECT_KEY, objEntity);
+
+        String res = renderTemplate(ClassGenerationAction.SUPERCLASS_TEMPLATE, context);
+        assertTrue(res.contains("org.apache.cayenne.exp.Property"));
+    }
+
+}


Mime
View raw message