-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/sboesebeck/morphium into…
… develop
- Loading branch information
Showing
2 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
test/de/caluga/test/mongo/suite/InterfacePolymorphismTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package de.caluga.test.mongo.suite; | ||
|
||
import de.caluga.morphium.MorphiumSingleton; | ||
import de.caluga.morphium.annotations.Entity; | ||
import de.caluga.morphium.annotations.Id; | ||
import de.caluga.morphium.annotations.caching.NoCache; | ||
import org.bson.types.ObjectId; | ||
import org.junit.Test; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Created with IntelliJ IDEA. | ||
* User: bfsmith | ||
* Date: 30.03.15 | ||
* Test interface polymorphism mechanism in Morphium | ||
*/ | ||
public class InterfacePolymorphismTest extends MongoTest { | ||
@Test | ||
public void polymorphTest() throws Exception { | ||
MorphiumSingleton.get().dropCollection(IfaceTestType.class); | ||
IfaceTestType ifaceTestType = new IfaceTestType(); | ||
ifaceTestType.setName("A Complex Type"); | ||
ifaceTestType.setPolyTest(new SubClass(11)); | ||
MorphiumSingleton.get().store(ifaceTestType); | ||
|
||
assert (MorphiumSingleton.get().createQueryFor(IfaceTestType.class).countAll() == 2); | ||
List<IfaceTestType> lst = MorphiumSingleton.get().createQueryFor(IfaceTestType.class).asList(); | ||
for (IfaceTestType tst : lst) { | ||
log.info("Class " + tst.getClass().toString()); | ||
} | ||
} | ||
|
||
@Entity | ||
public class IfaceTestType { | ||
@Id | ||
private ObjectId id; | ||
private String name; | ||
private IPolyTest polyTest; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public IPolyTest getPolyTest() { | ||
return polyTest; | ||
} | ||
|
||
public void setPolyTest(IPolyTest polyTest) { | ||
this.polyTest = polyTest; | ||
} | ||
} | ||
|
||
@Entity(polymorph = true) | ||
@NoCache | ||
public static interface IPolyTest { | ||
int getNumber(); | ||
} | ||
|
||
public static class SubClass implements IPolyTest { | ||
private int number; | ||
|
||
private SubClass() {} | ||
|
||
public SubClass(int num) { | ||
number = num; | ||
} | ||
|
||
public int getNumber() { | ||
return number; | ||
} | ||
|
||
public void setNumber(int number) { | ||
this.number = number; | ||
} | ||
} | ||
} |