-
Notifications
You must be signed in to change notification settings - Fork 277
Expand file tree
/
Copy pathLocalDatastoreServiceTest.java
More file actions
150 lines (123 loc) · 4.71 KB
/
Copy pathLocalDatastoreServiceTest.java
File metadata and controls
150 lines (123 loc) · 4.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package src;
import java.io.IOException;
import java.io.Writer;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.DefaultHttpClient;
import org.junit.Test;
import org.mockito.ArgumentMatcher;
import static org.mockito.Mockito.*;
import com.google.appengine.api.datastore.dev.HTTPClientDatastoreProxy;
import com.google.appengine.api.datastore.dev.LocalDatastoreService;
import com.google.appengine.repackaged.com.google.io.protocol.ProtocolMessage;
import com.google.appengine.tools.development.LocalRpcService.Status;
import com.google.apphosting.api.DatastorePb;
import com.google.storage.onestore.v3.OnestoreEntity.EntityProto;
import com.google.storage.onestore.v3.OnestoreEntity.Path;
import com.google.storage.onestore.v3.OnestoreEntity.Path.Element;
import com.google.storage.onestore.v3.OnestoreEntity.Property;
import com.google.storage.onestore.v3.OnestoreEntity.PropertyValue;
import com.google.storage.onestore.v3.OnestoreEntity.PropertyValue.UserValue;
import com.google.storage.onestore.v3.OnestoreEntity.Reference;
public class LocalDatastoreServiceTest
{
// @Test
/*
* Ignoring this test for now, there is a limitation where we can't mock out
* the static method call in HTTPClientDatastoreProxy in method getUser() so
* UserServiceImpl.getCurrentUser throws a nullpointer
*/
public void testPutImpl() throws ClientProtocolException, IOException
{
/*
* This test puts together the input arguments for putImpl, mocks out
* the HTTPClientDatastoreProxy and basically passes if there are no
* exceptions thrown. The reason there are no assertions is that neither
* the putImpl method or the doPost method return anything.
*/
// service with putImpl method
LocalDatastoreService service = new LocalDatastoreService();
// 1st arg to putImpl
Status status = getMockStatus();
// 2nd arg to putImpl
DatastorePb.PutRequest request = getMockRequest();
// mock out HttpClientDatastoreProxy
HTTPClientDatastoreProxy proxy = new HTTPClientDatastoreProxy("localhost", 8080, false);
DefaultHttpClient client = mock(DefaultHttpClient.class);
byte[] bytes = { 1, 2, 3, 4, 5 };
when(client.execute(any(HttpUriRequest.class), any(ResponseHandler.class))).thenReturn(bytes);
proxy.setClient(client);
service.setProxy(proxy);
// test method
service.putImpl(status, request);
}
public Status getMockStatus()
{
Status status = new Status();
status.setErrorCode(0);
status.setSuccessful(true);
return status;
}
public DatastorePb.PutRequest getMockRequest()
{
/*
* See comment at end of this class to see what this request actually
* looks like
*/
DatastorePb.PutRequest request = new DatastorePb.PutRequest();
request.setForce(false);
request.setMarkChanges(false);
request.setTrusted(false);
EntityProto ep = new EntityProto();
Reference ref = new Reference();
ref.setApp("javabook");
Path path = new Path();
Element elem = new Element();
elem.setType("Greeting");
path.addElement(elem);
ref.setPath(path);
Property contentProp = new Property();
PropertyValue value;
contentProp.setName("content");
value = new PropertyValue();
value.setStringValue("abcdefg");
contentProp.setValue(value);
contentProp.setMultiple(false);
Property userProperty = new Property();
userProperty.setName("author");
PropertyValue userPropertyValue = new PropertyValue();
UserValue userValue = new UserValue();
userValue.setEmail("test@example.com");
userValue.setAuthDomain("gmail.com");
userValue.setGaiaid(0);
userValue.setObfuscatedGaiaid("-1405876145");
userPropertyValue.setUserValue(userValue);
userProperty.setValue(userPropertyValue);
userProperty.setMultiple(false);
Property meaningProp = new Property();
meaningProp.setMeaning(7);
meaningProp.setName("date");
PropertyValue meaningPropValue = new PropertyValue();
meaningPropValue.setInt64Value(1234567);
meaningProp.setValue(meaningPropValue);
meaningProp.setMultiple(false);
ep.addProperty(contentProp);
ep.addProperty(userProperty);
ep.addProperty(meaningProp);
ep.setKey(ref);
request.addEntity(ep);
System.out.println(request.toString());
return request;
}
/*
* Sample request entity < key < app: "javabook" path < Element { type:
* "Greeting" } > > entity_group <
*
* > property < name: "content" value < stringValue: "aafaefaef" > multiple:
* false > property < name: "author" value < UserValue { email:
* "test@example.com" auth_domain: "gmail.com" gaiaid: 0 obfuscated_gaiaid:
* "-1405876145" } > multiple: false > property < meaning: 7 name: "date"
* value < int64Value: 0x4cd6276e39108 > multiple: false > >
*/
}