Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added tests and jUnit target for ant

  • Loading branch information...
commit fe7dc1f0bf3818caa2daa60bd5e922b263bd3d9a 1 parent 8816e58
ingo authored
4 conf.sh
@@ -76,8 +76,8 @@ echo "checking Java dependencies"
76 76 # OtpErlang.jar
77 77 OTPERLANGJAR=`ls $ERL_HOME/lib/erlang/lib/jinterface*/priv/OtpErlang.jar`
78 78 if [ $? -gt 0 ]; then
79   - "ERROR: OtpErlang.jar not found"
80   - "------ your Erlang distribution may not be properly installed"
  79 + echo "ERROR: OtpErlang.jar not found"
  80 + echo "------ your Erlang distribution may not be properly installed"
81 81 exit 1
82 82 fi
83 83 echo "found $OTPERLANGJAR"
89 java/build.xml
... ... @@ -1,36 +1,65 @@
1 1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 2 <project default="compile" name="nerlo build" basedir=".">
3   -
  3 +
4 4 <property name="src.dir" value="src"/>
  5 + <property name="test.dir" value="test"/>
5 6 <property name="class.dir" value="classes"/>
  7 + <property name="testclass.dir" value="test-classes"/>
6 8 <property name="dist.dir" value="dist"/>
7 9 <property name="lib.dir" value="lib"/>
8 10 <property name="deps.name" value="deps"/>
9 11 <property name="dist.deps.dir" value="${dist.dir}/${deps.name}"/>
10 12
11 13 <target name="compile">
12   - <mkdir dir="${class.dir}"/>
13   - <javac destdir="${class.dir}" debug="on" optimize="on" includeantruntime="false">
14   - <src path="${src.dir}"/>
15   - <classpath>
16   - <fileset dir="${lib.dir}">
17   - <include name="**/*.jar" />
18   - </fileset>
19   - </classpath>
20   - </javac>
21   - </target>
22   -
23   - <target name="clean">
24   - <delete dir="${class.dir}"/>
25   - <delete dir="${dist.dir}"/>
26   - </target>
27   -
  14 + <mkdir dir="${class.dir}"/>
  15 + <javac destdir="${class.dir}" debug="on" optimize="on" includeantruntime="false">
  16 + <src path="${src.dir}"/>
  17 + <classpath id="classpath">
  18 + <fileset dir="${lib.dir}">
  19 + <include name="**/*.jar" />
  20 + </fileset>
  21 + </classpath>
  22 + </javac>
  23 + </target>
  24 +
  25 + <target name="compile-test" depends="compile">
  26 + <mkdir dir="${testclass.dir}"/>
  27 + <javac destdir="${testclass.dir}" debug="on" optimize="on" includeantruntime="false">
  28 + <src path="${test.dir}"/>
  29 + <classpath id="testclasspath">
  30 + <fileset dir="${lib.dir}">
  31 + <include name="**/*.jar" />
  32 + </fileset>
  33 + <pathelement path="${class.dir}" />
  34 + <pathelement path="${testclass.dir}" />
  35 + </classpath>
  36 + </javac>
  37 + </target>
  38 +
  39 + <target name="test" depends="compile-test">
  40 + <junit>
  41 + <classpath refid="testclasspath" />
  42 +
  43 +
  44 + <batchtest>
  45 + <fileset dir="${testclass.dir}"/>
  46 + <formatter type="brief" usefile="false"/>
  47 + </batchtest>
  48 + </junit>
  49 + </target>
  50 +
  51 + <target name="clean">
  52 + <delete dir="${class.dir}"/>
  53 + <delete dir="${testclass.dir}"/>
  54 + <delete dir="${dist.dir}"/>
  55 + </target>
  56 +
28 57 <target name="jar" depends="compile">
29   - <mkdir dir="${dist.dir}"/>
30   - <jar destfile="${dist.dir}/nerlo.jar">
31   - <manifest>
32   - <attribute name="Main-Class" value="org.ister.ej.Main"/>
33   - <attribute name="Class-Path"
  58 + <mkdir dir="${dist.dir}"/>
  59 + <jar destfile="${dist.dir}/nerlo.jar">
  60 + <manifest>
  61 + <attribute name="Main-Class" value="org.ister.ej.Main"/>
  62 + <attribute name="Class-Path"
34 63 value=". ${deps.name}/OtpErlang.jar
35 64 ${deps.name}/commons-cli-1.2.jar
36 65 ${deps.name}/log4j-1.2.15.jar
@@ -39,17 +68,17 @@
39 68 ${deps.name}/lucene-core-2.9.3.jar
40 69 ${deps.name}/geronimo-jta_1.1_spec-1.1.1.jar
41 70 "/>
42   - </manifest>
43   - <fileset dir="${class.dir}"/>
44   - </jar>
45   - <delete dir="${dist.dir}/deps"/>
46   - <mkdir dir="${dist.dir}/deps"/>
47   - <copy file="${lib.dir}/OtpErlang.jar" todir="${dist.deps.dir}"/>
48   - <copy file="${lib.dir}/commons-cli-1.2.jar" todir="${dist.deps.dir}"/>
  71 + </manifest>
  72 + <fileset dir="${class.dir}"/>
  73 + </jar>
  74 + <delete dir="${dist.dir}/deps"/>
  75 + <mkdir dir="${dist.dir}/deps"/>
  76 + <copy file="${lib.dir}/OtpErlang.jar" todir="${dist.deps.dir}"/>
  77 + <copy file="${lib.dir}/commons-cli-1.2.jar" todir="${dist.deps.dir}"/>
49 78 <copy file="${lib.dir}/log4j-1.2.15.jar" todir="${dist.deps.dir}"/>
50 79 <copy file="${lib.dir}/neo4j-kernel-1.1.jar" todir="${dist.deps.dir}"/>
51 80 <copy file="${lib.dir}/neo4j-index-1.1.jar" todir="${dist.deps.dir}"/>
52 81 <copy file="${lib.dir}/lucene-core-2.9.3.jar" todir="${dist.deps.dir}"/>
53 82 <copy file="${lib.dir}/geronimo-jta_1.1_spec-1.1.1.jar" todir="${dist.deps.dir}"/>
54   - </target>
  83 + </target>
55 84 </project>
2  java/lib/DEPENDENCIES
@@ -5,6 +5,6 @@ lucene-core-2.9.3.jar
5 5 geronimo-jta_1.1_spec-1.1.1.jar
6 6 neo4j-kernel-1.1.jar
7 7 neo4j-index-1.1.jar
8   -
  8 +junit-4.8.2.jar
9 9
10 10
7 java/src/org/ister/ej/MsgRef.java
@@ -54,4 +54,11 @@ public Object clone() {
54 54 return new MsgRef(this);
55 55 }
56 56
  57 + @Override
  58 + public boolean equals(Object other) {
  59 + return pid.equals(((MsgRef)other).pid)
  60 + && ref.equals(((MsgRef)other).ref)
  61 + && t.equals(((MsgRef)other).t);
  62 + }
  63 +
57 64 }
193 java/test/org/ister/ej/MsgTest.java
... ... @@ -0,0 +1,193 @@
  1 +package org.ister.ej;
  2 +
  3 +import static org.junit.Assert.*;
  4 +
  5 +import java.sql.Ref;
  6 +import java.util.HashMap;
  7 +import java.util.Map;
  8 +
  9 +import org.junit.After;
  10 +import org.junit.Before;
  11 +import org.junit.Test;
  12 +
  13 +import com.ericsson.otp.erlang.*;
  14 +
  15 +import org.ister.ej.MsgTag;
  16 +
  17 +public class MsgTest {
  18 +
  19 + private final OtpErlangString ok = new OtpErlangString(MsgTag.OK);
  20 + private final OtpErlangString call = new OtpErlangString(MsgTag.CALL);
  21 + private final OtpErlangList payload = new OtpErlangList();
  22 + private final OtpErlangObject[] os = new OtpErlangObject[2];
  23 +
  24 + private final OtpErlangPid pid = new OtpErlangPid("foo",0,0,0);
  25 +
  26 + private OtpErlangTuple tuple = null;
  27 +
  28 +// private final OtpErlangString s2 = new OtpErlangString("2");
  29 +// private final OtpErlangString s3 = new OtpErlangString("3");
  30 +// private final OtpErlangString s4 = new OtpErlangString("4");
  31 + private final MsgRef ref1 = new MsgRef(new OtpErlangPid("foo",0,0,0), new OtpErlangRef("dummy", 0, 0));
  32 + private final MsgRef ref2 = new MsgRef(new OtpErlangPid("foo",1,0,0), new OtpErlangRef("dummy", 1, 0));
  33 +
  34 + @Before
  35 + public void setUp() throws Exception {
  36 + os[0] = ok;
  37 + os[1] = payload;
  38 + tuple = new OtpErlangTuple(os);
  39 + }
  40 +
  41 + @After
  42 + public void tearDown() throws Exception {
  43 + }
  44 +
  45 + @Test
  46 + public void testHashCode() {
  47 + Msg m1 = new Msg(pid, ref1, tuple);
  48 + Msg m2 = new Msg(pid, ref2, tuple);
  49 + assertTrue(m1.hashCode() != m2.hashCode());
  50 + }
  51 +
  52 + @Test
  53 + public void testMsgOtpErlangPidMsgRefOtpErlangTuple() {
  54 + Msg m1 = new Msg(pid, ref1, tuple);
  55 + assertTrue(m1 instanceof Msg);
  56 + }
  57 +
  58 + @Test
  59 + public void testMsgOtpErlangTuple() {
  60 + OtpErlangObject[] ref = new OtpErlangObject[2];
  61 + ref[0] = pid;
  62 + ref[1] = new OtpErlangRef("dummy", 0, 0);
  63 + OtpErlangObject[] m = new OtpErlangObject[3];
  64 + m[0] = pid;
  65 + m[1] = new OtpErlangTuple(ref);
  66 + m[2] = tuple;
  67 + OtpErlangTuple t = new OtpErlangTuple(m);
  68 + Msg m1 = new Msg(t);
  69 + assertTrue(m1 instanceof Msg);
  70 + }
  71 +
  72 + @Test
  73 + public void testMatchIntOtpErlangObject() {
  74 + Map<String, Object> map = new HashMap<String, Object>(2);
  75 + map.put("call", new Integer(1));
  76 + Msg m = Msg.factory(pid, ref1, new MsgTag(MsgTag.OK), map);
  77 + assertTrue(m.match(0, new OtpErlangAtom(MsgTag.OK)));
  78 + }
  79 +
  80 + @Test
  81 + public void testMatchStringObject() {
  82 + Map<String, Object> map = new HashMap<String, Object>(2);
  83 + map.put("call", "foo");
  84 + Msg m = Msg.factory(pid, ref1, new MsgTag(MsgTag.OK), map);
  85 + assertTrue(m.match("call", "foo"));
  86 + assertFalse(m.match("call", 2));
  87 + }
  88 +
  89 + @Test
  90 + public void testHas() {
  91 + Map<String, Object> map = new HashMap<String, Object>(2);
  92 + map.put("call", "me");
  93 + Msg m = Msg.factory(pid, ref1, new MsgTag(MsgTag.OK), map);
  94 + assertTrue(m.has("call"));
  95 + assertFalse(m.has("dummy"));
  96 + }
  97 +
  98 + @Test
  99 + public void testGet() {
  100 + Map<String, Object> map = new HashMap<String, Object>(2);
  101 + map.put("call", "me");
  102 + Msg m = Msg.factory(pid, ref1, new MsgTag(MsgTag.OK), map);
  103 + assertEquals(m.get("call"), "me");
  104 + }
  105 +
  106 + @Test
  107 + public void testGetFrom() {
  108 + Msg m1 = new Msg(pid, ref1, tuple);
  109 + assertTrue(m1.getFrom().node() == "foo");
  110 + }
  111 +
  112 + @Test
  113 + public void testGetRefGetRefTuple() {
  114 + Msg m1 = new Msg(pid, ref1, tuple);
  115 + assertTrue(m1.getRef().toTuple().equals(m1.getRefTuple()));
  116 + }
  117 +
  118 + @Test
  119 + public void testGetMsg() {
  120 + Msg m1 = new Msg(pid, ref1, tuple);
  121 + assertTrue(m1.getMsg().equals(tuple));
  122 + }
  123 +
  124 + @Test
  125 + public void testGetMap() {
  126 + Map<String, Object> map = new HashMap<String, Object>(2);
  127 + map.put("call", "me");
  128 + Msg m = Msg.factory(pid, ref1, new MsgTag(MsgTag.OK), map);
  129 + assertTrue(m.getMap().equals(map));
  130 + }
  131 +
  132 + @Test
  133 + public void testGetTag() {
  134 + Map<String, Object> map = new HashMap<String, Object>(2);
  135 + map.put("call", "me");
  136 + Msg m = Msg.factory(pid, ref1, new MsgTag(MsgTag.OK), map);
  137 + assertTrue(m.getTag().equals(MsgTag.OK));
  138 + }
  139 +
  140 + @Test
  141 + public void testToTuple() {
  142 + Map<String, Object> map = new HashMap<String, Object>(2);
  143 + map.put("call", "me");
  144 + Msg m = Msg.factory(pid, ref1, new MsgTag(MsgTag.OK), map);
  145 + assertTrue(m.toTuple() instanceof OtpErlangTuple);
  146 + }
  147 +
  148 + @Test
  149 + public void testToString() {
  150 + Map<String, Object> map = new HashMap<String, Object>(2);
  151 + map.put("call", "me");
  152 + Msg m = Msg.factory(pid, ref1, new MsgTag(MsgTag.OK), map);
  153 + assertTrue(m.toString() instanceof java.lang.String);
  154 + }
  155 +
  156 + @Test
  157 + public void testFactory() {
  158 + Map<String, Object> map = new HashMap<String, Object>(2);
  159 + map.put("call", "me");
  160 + Msg m = Msg.factory(pid, ref1, new MsgTag(MsgTag.OK), map);
  161 + assertTrue(m instanceof Msg);
  162 + }
  163 +
  164 + @Test
  165 + public void testAnswer() {
  166 + Map<String, Object> map = new HashMap<String, Object>(2);
  167 + map.put("call", "me");
  168 + Msg m = Msg.factory(pid, ref1, new MsgTag(MsgTag.OK), map);
  169 + Msg a = Msg.answer(m.getFrom(), MsgTag.OK, map, m);
  170 + assertTrue(m.getFrom().equals(a.getFrom()));
  171 + assertTrue(m.getRef().equals(a.getRef()));
  172 + }
  173 +
  174 + @Test
  175 + public void testFragment() {
  176 + Map<String, Object> map = new HashMap<String, Object>(2);
  177 + map.put("call", "me");
  178 + Msg m = Msg.factory(pid, ref1, new MsgTag(MsgTag.OK), map);
  179 + Msg a = Msg.fragment(m.getFrom(), map, m);
  180 + assertTrue(a.getTag().equals(MsgTag.FRAGMENT));
  181 + }
  182 +
  183 + @Test
  184 + public void testLastFragment() {
  185 + Map<String, Object> map = new HashMap<String, Object>(2);
  186 + map.put("call", "me");
  187 + Msg m = Msg.factory(pid, ref1, new MsgTag(MsgTag.OK), map);
  188 + Msg a = Msg.lastFragment(m.getFrom(), m);
  189 + assertTrue(a.getTag().equals(MsgTag.OK));
  190 + assertTrue(a.match("result", "EJCALLBACKSTOP"));
  191 + }
  192 +
  193 +}

0 comments on commit fe7dc1f

Please sign in to comment.
Something went wrong with that request. Please try again.