Skip to content

Commit e2463f8

Browse files
committed
Add some domain classes + tests
Add powermokito library
1 parent df3a193 commit e2463f8

File tree

13 files changed

+295
-3
lines changed

13 files changed

+295
-3
lines changed

README.markdown

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Technologies
1414

1515
GWT 2.4
1616
-------
17-
Framework for the server side.
17+
Framework to build advanced web application in java.
1818

1919
GIN
2020
---
@@ -31,6 +31,24 @@ Morphia
3131
ORM like for mongoDB.
3232
http://code.google.com/p/morphia
3333

34+
Testing
35+
----
36+
37+
JUnit 4.10
38+
------
39+
Excellent java testing framework
40+
http://junit.org
41+
42+
Mockito
43+
-----
44+
Mock object on the server side.
45+
http://code.google.com/p/mockito/
46+
47+
Power Mockito
48+
-----
49+
Mock the not-mocketable !
50+
http://code.google.com/p/powermock
51+
3452
Framework underline.
3553
--------
3654
In this example I try to demonstrate how a web application can be created highly efficiently.

src/com/arm/nimbus/collab/client/TasksSummaryView.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import com.google.gwt.user.cellview.client.CellTable;
1919
import com.google.gwt.user.cellview.client.TextColumn;
2020
import com.google.gwt.view.client.ListDataProvider;
21-
import com.google.gwt.http.*;
2221
import com.google.gwt.http.client.Request;
2322
import com.google.gwt.http.client.RequestBuilder;
2423
import com.google.gwt.http.client.RequestCallback;

src/com/arm/nimbus/collab/server/MongoService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static DB get(){
3232

3333
Mongo m = null;
3434
try {
35-
m = new Mongo( "localhost" );
35+
m = new Mongo( "localhost", 27017);
3636
} catch (UnknownHostException e) {
3737
log.log(Level.SEVERE, e.getMessage());
3838
e.printStackTrace();
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.arm.nimbus.collab.server.model;
2+
3+
import com.google.code.morphia.annotations.Version;
4+
import com.google.code.morphia.annotations.Id;
5+
import org.bson.types.ObjectId;
6+
7+
8+
/**
9+
* Domain common fields.
10+
*
11+
* @creator victor
12+
*/
13+
public class PersistentEntity {
14+
15+
/**
16+
* Generate a unique ID
17+
* Best description of the API
18+
*/
19+
@Id
20+
private String id;
21+
22+
/***
23+
* Set a version of the model model.
24+
* Simplify future migration.
25+
*/
26+
@Version
27+
private Long version;
28+
29+
public PersistentEntity() {
30+
id = new ObjectId().toString();
31+
}
32+
33+
public String getId() {
34+
return id;
35+
}
36+
37+
public Long getVersion() {
38+
return version;
39+
}
40+
41+
public void setVersion(Long version) {
42+
this.version = version;
43+
}
44+
45+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.arm.nimbus.collab.server.model;
2+
3+
import javax.validation.constraints.NotNull;
4+
import javax.validation.constraints.Null;
5+
6+
/**
7+
* TODO description
8+
*
9+
* @creator victor
10+
*/
11+
public class Product extends PersistentEntity {
12+
13+
// Product name
14+
@NotNull
15+
String name;
16+
17+
// A product code (version, SAP ID)
18+
@Null
19+
String code;
20+
21+
public Product() {
22+
super();
23+
}
24+
25+
public String getName() {
26+
return name;
27+
}
28+
29+
public void setName(String name) {
30+
this.name = name;
31+
}
32+
33+
public String getCode() {
34+
return code;
35+
}
36+
37+
public void setCode(String code) {
38+
this.code = code;
39+
}
40+
41+
/***
42+
* Find a product
43+
* @param id
44+
* @return
45+
*/
46+
public static Product findById(String id){
47+
//TODO Implement
48+
return new Product();
49+
}
50+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.arm.nimbus.collab.server.model;
2+
3+
import javax.validation.constraints.NotNull;
4+
5+
/**
6+
* TODO description
7+
*
8+
* @creator victor
9+
*/
10+
public class User extends PersistentEntity{
11+
12+
@NotNull
13+
String username;
14+
15+
@NotNull
16+
String role;
17+
18+
public User() {
19+
super();
20+
}
21+
22+
public String getUsername() {
23+
return username;
24+
}
25+
26+
public void setUsername(String username) {
27+
this.username = username;
28+
}
29+
30+
public String getRole() {
31+
return role;
32+
}
33+
34+
public void setRole(String role) {
35+
this.role = role;
36+
}
37+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package unit.server.model;
2+
3+
import com.arm.nimbus.collab.server.model.PersistentEntity;
4+
import com.arm.nimbus.collab.server.model.User;
5+
import org.junit.*;
6+
7+
/**
8+
* TODO description
9+
*
10+
* @creator victor
11+
*/
12+
public class PersistentEntityUnitTest {
13+
14+
@Test
15+
public void constructor(){
16+
17+
PersistentEntity entity = new PersistentEntity();
18+
19+
Assert.assertNotNull(entity.getId());
20+
Assert.assertNull(entity.getVersion());
21+
22+
}
23+
24+
@Test
25+
public void version(){
26+
27+
PersistentEntity entity = new PersistentEntity();
28+
Long version = 1L;
29+
entity.setVersion(version);
30+
Assert.assertEquals(version, entity.getVersion());
31+
32+
}
33+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package unit.server.model;
2+
3+
import com.arm.nimbus.collab.server.model.PersistentEntity;
4+
import com.arm.nimbus.collab.server.model.Product;
5+
import org.junit.*;
6+
import org.junit.runner.RunWith;
7+
import org.mockito.Mockito;
8+
import org.powermock.api.mockito.PowerMockito;
9+
import org.powermock.core.classloader.annotations.PrepareForTest;
10+
import org.powermock.modules.junit4.PowerMockRunner;
11+
12+
/**
13+
* TODO description
14+
*
15+
* @creator victor
16+
*/
17+
@RunWith(PowerMockRunner.class)
18+
@PrepareForTest(Product.class)
19+
public class ProductUnitTest{
20+
21+
Product p;
22+
23+
@Before
24+
public void setUp() throws Exception {
25+
p = new Product();
26+
}
27+
28+
@After
29+
public void tearDown() throws Exception {
30+
}
31+
32+
@Test
33+
public void name() throws Exception {
34+
String name = "mike";
35+
p.setName(name);
36+
Assert.assertEquals(name, p.getName());
37+
}
38+
39+
@Test
40+
public void code() throws Exception {
41+
String code = "c32p56";
42+
p.setCode(code);
43+
Assert.assertEquals(code, p.getCode());
44+
}
45+
46+
@Test
47+
public void isPersistentEntity(){
48+
PersistentEntity entity = p;
49+
Assert.assertNotNull(entity.getId());
50+
Assert.assertNull(entity.getVersion());
51+
}
52+
53+
@Test
54+
/*
55+
* Mock a static method.
56+
* Really new way of testing your java.
57+
* @doc http://code.google.com/p/powermock/wiki/MockitoUsage
58+
*/
59+
60+
public void findByID(){
61+
PowerMockito.mockStatic(Product.class);
62+
Mockito.when(Product.findById("id")).thenReturn(new Product());
63+
64+
Product r = Product.findById("id");
65+
Assert.assertEquals(p.getCode(), r.getCode());
66+
Assert.assertEquals(p.getName(), r.getName());
67+
}
68+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package unit.server.model;
2+
3+
import com.arm.nimbus.collab.server.model.PersistentEntity;
4+
import com.arm.nimbus.collab.server.model.User;
5+
import org.junit.Assert;
6+
import org.junit.Before;
7+
import org.junit.Test;
8+
9+
/**
10+
* TODO description
11+
*
12+
* @creator victor
13+
*/
14+
public class UserUnitTest {
15+
User u;
16+
17+
@Before
18+
public void setUp(){
19+
u = new User();
20+
}
21+
22+
@Test
23+
public void username() throws Exception {
24+
String username = "vicben01";
25+
u.setUsername(username);
26+
Assert.assertEquals(username, u.getUsername());
27+
}
28+
29+
@Test
30+
public void role() throws Exception {
31+
String role = "developer";
32+
u.setRole(role);
33+
Assert.assertEquals(role, u.getRole());
34+
}
35+
36+
@Test
37+
public void isPersistentEntity(){
38+
PersistentEntity entity = u;
39+
Assert.assertNotNull(entity.getId());
40+
Assert.assertNull(entity.getVersion());
41+
}
42+
}
315 KB
Binary file not shown.

0 commit comments

Comments
 (0)