Skip to content

Commit 4213237

Browse files
authored
Merge pull request #66 from DaVicki/test-batchoperation
Test batchoperation
2 parents cd7c214 + 7f66b25 commit 4213237

File tree

2 files changed

+190
-1
lines changed

2 files changed

+190
-1
lines changed

ipp-v3-java-devkit/src/main/java/com/intuit/ipp/services/BatchOperation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
import com.intuit.ipp.util.StringUtils;
4040

4141
/**
42-
* Class to prepare the BatchItemrequets and get the responses for the corresponding bIds.
42+
* Class to prepare the BatchItemrequests and get the responses for the corresponding bIds.
4343
* The response is segregated to corresponding result types so that user can validate the corresponding batch item using the bId.
4444
*
4545
*/
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2017 Intuit
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*******************************************************************************/
16+
package com.intuit.ipp.services;
17+
18+
import com.intuit.ipp.core.IEntity;
19+
import com.intuit.ipp.data.Account;
20+
import com.intuit.ipp.data.Attachable;
21+
import com.intuit.ipp.data.BatchItemRequest;
22+
import com.intuit.ipp.data.Customer;
23+
import com.intuit.ipp.data.OperationEnum;
24+
import com.intuit.ipp.exception.FMSException;
25+
import org.testng.Assert;
26+
import org.testng.annotations.BeforeMethod;
27+
import org.testng.annotations.Test;
28+
29+
import java.util.ArrayList;
30+
import java.util.List;
31+
32+
public class BatchOperationTest {
33+
34+
private BatchOperation batchOperation;
35+
36+
@BeforeMethod
37+
public void setUp() {
38+
batchOperation = new BatchOperation();
39+
}
40+
41+
@Test
42+
void testAddEntity() {
43+
int batchSize = 2;
44+
45+
for(int i=0; i<batchSize; i++) {
46+
String bid = "123" + i;
47+
Customer entity = new Customer();
48+
OperationEnum create = OperationEnum.CREATE;
49+
50+
batchOperation.addEntity(entity, create, bid);
51+
52+
Assert.assertNotNull(batchOperation.getBIds());
53+
Assert.assertNotNull(batchOperation.getBatchItemRequests());
54+
Assert.assertEquals(batchOperation.getBIds().size(), i+1);
55+
Assert.assertEquals(batchOperation.getBatchItemRequests().size(), i+1);
56+
57+
BatchItemRequest batchItemRequest = batchOperation.getBatchItemRequests().get(i);
58+
Assert.assertNotNull(batchItemRequest);
59+
Assert.assertEquals(batchItemRequest.getBId(), bid);
60+
Assert.assertNotNull(batchItemRequest.getIntuitObject());
61+
Assert.assertEquals(batchItemRequest.getOperation(), create);
62+
63+
List<String> bids = batchOperation.getBIds();
64+
Assert.assertNotNull(bids);
65+
Assert.assertEquals(bids.size(), i+1);
66+
}
67+
}
68+
69+
@Test
70+
void testAddQuery() {
71+
int batchSize = 2;
72+
73+
for(int i=0; i<batchSize; i++) {
74+
String bid = "123" + i;
75+
String query = "Select * from Invoice " + i;
76+
77+
batchOperation.addQuery(query, bid);
78+
79+
Assert.assertNotNull(batchOperation.getBIds());
80+
Assert.assertNotNull(batchOperation.getBatchItemRequests());
81+
Assert.assertEquals(batchOperation.getBIds().size(), i+1);
82+
Assert.assertEquals(batchOperation.getBatchItemRequests().size(), i+1);
83+
84+
BatchItemRequest batchItemRequest = batchOperation.getBatchItemRequests().get(i);
85+
Assert.assertNotNull(batchItemRequest);
86+
Assert.assertEquals(batchItemRequest.getBId(), bid);
87+
Assert.assertNotNull(batchItemRequest.getQuery());
88+
Assert.assertEquals(batchItemRequest.getQuery(), query);
89+
90+
List<String> bids = batchOperation.getBIds();
91+
Assert.assertNotNull(bids);
92+
Assert.assertEquals(bids.size(), i+1);
93+
}
94+
}
95+
96+
@Test
97+
void testReportQuery() {
98+
int batchSize = 2;
99+
100+
for(int i=0; i<batchSize; i++) {
101+
String bid = "123" + i;
102+
String reportQuery = "sample report query " + i;
103+
104+
batchOperation.addReportQuery(reportQuery, bid);
105+
106+
Assert.assertNotNull(batchOperation.getBIds());
107+
Assert.assertNotNull(batchOperation.getBatchItemRequests());
108+
Assert.assertEquals(batchOperation.getBIds().size(), i+1);
109+
Assert.assertEquals(batchOperation.getBatchItemRequests().size(), i+1);
110+
111+
BatchItemRequest batchItemRequest = batchOperation.getBatchItemRequests().get(i);
112+
Assert.assertNotNull(batchItemRequest);
113+
Assert.assertEquals(batchItemRequest.getBId(), bid);
114+
Assert.assertNotNull(batchItemRequest.getReportQuery());
115+
Assert.assertEquals(batchItemRequest.getReportQuery(), reportQuery);
116+
117+
List<String> bids = batchOperation.getBIds();
118+
Assert.assertNotNull(bids);
119+
Assert.assertEquals(bids.size(), i+1);
120+
}
121+
}
122+
123+
@Test(expectedExceptions = FMSException.class)
124+
void testCDCQuery_NullEntities() throws FMSException {
125+
batchOperation.addCDCQuery(null, "", "");
126+
}
127+
128+
@Test(expectedExceptions = FMSException.class)
129+
void testCDCQuery_EmptyEntities() throws FMSException {
130+
List<IEntity> empty = new ArrayList<>();
131+
batchOperation.addCDCQuery(empty, "", "");
132+
}
133+
134+
@Test(expectedExceptions = FMSException.class)
135+
void testCDCQuery_NullCDCDate() throws FMSException {
136+
List<IEntity> entities = new ArrayList<>();
137+
entities.add(new Account());
138+
entities.add(new Attachable());
139+
140+
batchOperation.addCDCQuery(entities, null, "");
141+
}
142+
143+
@Test(expectedExceptions = FMSException.class)
144+
void testCDCQuery_EmptyCDCDate() throws FMSException {
145+
List<IEntity> entities = new ArrayList<>();
146+
entities.add(new Account());
147+
entities.add(new Attachable());
148+
149+
batchOperation.addCDCQuery(entities, "", "");
150+
}
151+
152+
@Test(expectedExceptions = FMSException.class)
153+
void testCDCQuery_InvalidDate() throws FMSException {
154+
String invalidDate = "2000~01~01";
155+
156+
List<IEntity> entities = new ArrayList<>();
157+
entities.add(new Account());
158+
entities.add(new Attachable());
159+
160+
batchOperation.addCDCQuery(entities, invalidDate, "");
161+
}
162+
163+
@Test
164+
void testCDCQuery() throws FMSException {
165+
String bid = "123";
166+
String cdcDate = "2000-01-01T00:00:00.000-0700";
167+
168+
List<IEntity> entities = new ArrayList<>();
169+
entities.add(new Account());
170+
entities.add(new Attachable());
171+
172+
batchOperation.addCDCQuery(entities, cdcDate, bid);
173+
174+
Assert.assertNotNull(batchOperation.getBIds());
175+
Assert.assertNotNull(batchOperation.getBatchItemRequests());
176+
Assert.assertEquals(batchOperation.getBIds().size(), 1);
177+
Assert.assertEquals(batchOperation.getBatchItemRequests().size(), 1);
178+
179+
BatchItemRequest batchItemRequest = batchOperation.getBatchItemRequests().get(0);
180+
Assert.assertNotNull(batchItemRequest);
181+
Assert.assertEquals(batchItemRequest.getBId(), bid);
182+
Assert.assertNotNull(batchItemRequest.getCDCQuery());
183+
Assert.assertNotEquals(batchItemRequest.getCDCQuery().getEntities(), Account.class.getSimpleName() + Attachable.class.getSimpleName());
184+
185+
List<String> bids = batchOperation.getBIds();
186+
Assert.assertNotNull(bids);
187+
Assert.assertEquals(bids.size(), 1);
188+
}
189+
}

0 commit comments

Comments
 (0)