11package com .odoojava .api ;
22
3- import com .odoojava .api .Response ;
4- import com .odoojava .api .OdooApiException ;
5- import com .odoojava .api .Row ;
6- import com .odoojava .api .OdooCommand ;
7- import com .odoojava .api .ObjectAdapter ;
8- import com .odoojava .api .FieldCollection ;
93import static org .assertj .core .api .Assertions .assertThat ;
104import static org .assertj .core .api .Assertions .catchThrowable ;
5+ import com .odoojava .api .DemoDbGetter .DemoDbInfoRequester ;
6+ import com .odoojava .api .OdooXmlRpcProxy .RPCProtocol ;
117
128import java .util .HashMap ;
139
1410import org .apache .xmlrpc .XmlRpcException ;
1511import org .assertj .core .api .SoftAssertions ;
12+ import org .junit .BeforeClass ;
1613import org .junit .Test ;
1714
1815public class ObjectAdapterTest {
1916 private static final String OTHER_SIGNAL_NAME = "otherSignalName" ;
2017 private static final String OTHER_MODEL_NAME = "otherModel" ;
2118 private static final String TEST_MODEL_NAME = "testModelName" ;
2219 private static final String TEST_SIGNAL_NAME = "signal" ;
20+ private static RPCProtocol protocol ;
21+ private static String host ;
22+ private static Integer port ;
23+ private static String databaseName ;
24+ private static String userName ;
25+ private static String password ;
26+
27+ private static Session session ;
2328
2429 boolean validated = false ;
2530
31+ @ BeforeClass
32+ public static void setUp () throws Exception {
33+ DemoDbGetter .getDemoDb (new DemoDbConnectionDataSetter ());
34+ session = new Session (protocol ,
35+ host , port , databaseName , userName ,password );
36+
37+ session .startSession ();
38+ }
39+
40+
41+
2642 private final class TestAdapter extends ObjectAdapter {
2743
2844 public TestAdapter () throws OdooApiException , XmlRpcException {
@@ -39,7 +55,10 @@ public FieldCollection getFields() throws XmlRpcException {
3955 return null ;
4056 }
4157 }
58+
59+
4260
61+
4362 private abstract class AbstractTestCommand extends OdooCommand {
4463 boolean searchCalledOnce = false ;
4564 boolean searchCalledTwiceOrMore = false ;
@@ -155,6 +174,56 @@ public void executeWorkflow(final String objectName, final String signal, final
155174 }
156175 }
157176
177+
178+
179+
180+ /**
181+ * Test of searchObject method, of class OdooCommand.
182+ */
183+ @ Test
184+ public void testSearchObject () throws Exception {
185+ ObjectAdapter partnerAdapter = session .getObjectAdapter ("res.partner" );
186+ FilterCollection filters = new FilterCollection ();
187+ filters .add ("id" , "<=" , 2 );
188+ RowCollection partners = partnerAdapter .searchAndReadObject (
189+ filters , new String [] { "name" , "email" });
190+
191+ SoftAssertions softAssertions = new SoftAssertions ();
192+ softAssertions .assertThat (partners .isEmpty ()).as ("Is successful" ).isFalse ();
193+ softAssertions .assertAll ();
194+ }
195+
196+
197+ @ Test
198+ public void should_return_model_list () throws Exception {
199+ // use SoftAssertions instead of direct assertThat methods
200+ // to collect all failing assertions in one go
201+ SoftAssertions softly = new SoftAssertions ();
202+
203+ assert (true );
204+ }
205+
206+ @ Test
207+ public void test_translated_name () throws Exception {
208+ // use SoftAssertions instead of direct assertThat methods
209+ // to collect all failing assertions in one go
210+ SoftAssertions softly = new SoftAssertions ();
211+
212+ String objectName = "product.product" ;
213+ ObjectAdapter prodAdapter = session .getObjectAdapter (objectName );
214+ String [] fields = new String []{"name" , "display_name" };
215+ Integer [] ids = new Integer [] { 32 };
216+ FilterCollection filters = new FilterCollection ();
217+ RowCollection prod_ids = prodAdapter .readObject (
218+ ids ,
219+ fields );
220+ Row prod_id = prod_ids .get (0 );
221+
222+ Object [] readResult = (Object []) session .executeCommand (objectName , "read" , new Object []{ids , fields });
223+ System .out .println ("prod_id name " + prod_id .get ("name" ));
224+ assert (true );
225+ }
226+
158227 @ Test
159228 public void should_throw_if_signal_doesnt_exist_for_that_object () throws Exception {
160229 // Wrong signal
@@ -191,5 +260,41 @@ public void should_call_execute_worflow_on_command() throws Exception {
191260 adapter .executeWorkflow (row , TEST_SIGNAL_NAME );
192261 assertThat (command .executeWorkflowCalled ).as ("Command's executeWorkflow has been called" ).isTrue ();
193262 }
263+
264+ /**
265+ * Only used to set the static data for connection on the main class
266+ */
267+ private static class DemoDbConnectionDataSetter implements DemoDbInfoRequester {
268+ @ Override
269+ public void setProtocol (RPCProtocol protocol ) {
270+ ObjectAdapterTest .protocol = protocol ;
271+ }
272+
273+ @ Override
274+ public void setHost (String host ) {
275+ ObjectAdapterTest .host = host ;
276+ }
277+
278+ @ Override
279+ public void setPort (Integer port ) {
280+ ObjectAdapterTest .port = port ;
281+ }
282+
283+ @ Override
284+ public void setDatabaseName (String databaseName ) {
285+ ObjectAdapterTest .databaseName = databaseName ;
286+ }
287+
288+ @ Override
289+ public void setUserName (String userName ) {
290+ ObjectAdapterTest .userName = userName ;
291+ }
292+
293+ @ Override
294+ public void setPassword (String password ) {
295+ ObjectAdapterTest .password = password ;
296+ }
297+ }
298+
194299
195300}
0 commit comments