Search in sources :

Example 6 with RecordRef

use of com.netsuite.webservices.test.platform.core.RecordRef in project components by Talend.

the class NetSuiteClientServiceTest method testGetList.

@Test
public void testGetList() throws Exception {
    TypeDesc typeDesc = clientService.getMetaDataSource().getTypeInfo("PurchaseOrder");
    TypeDesc refTypeDesc = clientService.getMetaDataSource().getTypeInfo("RecordRef");
    List<PurchaseOrder> recordList = makeNsObjects(new NsObjectComposer<PurchaseOrder>(clientService.getMetaDataSource(), typeDesc), 10);
    List<RecordRef> recordRefList = makeNsObjects(new NsObjectComposer<RecordRef>(clientService.getMetaDataSource(), refTypeDesc), 10);
    GetListResponse response = new GetListResponse();
    response.setReadResponseList(createSuccessReadResponseList(recordList));
    when(port.getList(notNull(GetListRequest.class))).thenReturn(response);
    clientService.getList(recordRefList);
    verify(port, times(1)).login(notNull(LoginRequest.class));
    verify(port, times(1)).getList(notNull(GetListRequest.class));
    List<NsReadResponse<Record>> readResponses = clientService.getList(null);
    assertTrue(readResponses.isEmpty());
}
Also used : GetListResponse(com.netsuite.webservices.test.platform.messages.GetListResponse) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) RecordRef(com.netsuite.webservices.test.platform.core.RecordRef) PurchaseOrder(com.netsuite.webservices.test.transactions.purchases.PurchaseOrder) LoginRequest(com.netsuite.webservices.test.platform.messages.LoginRequest) GetListRequest(com.netsuite.webservices.test.platform.messages.GetListRequest) Test(org.junit.Test)

Example 7 with RecordRef

use of com.netsuite.webservices.test.platform.core.RecordRef in project components by Talend.

the class ValueConverterTest method testJsonConverterNestedObjectConcreteType.

@Test
public void testJsonConverterNestedObjectConcreteType() throws Exception {
    NsObjectInputTransducer transducer = new NsObjectInputTransducer(clientService, schema, typeDesc.getTypeName());
    ObjectMapper objectMapper = new ObjectMapper();
    RecordRef recordRef1 = new RecordRef();
    recordRef1.setInternalId("12345");
    recordRef1.setName("R&D");
    ObjectNode recordRefNode1 = JsonNodeFactory.instance.objectNode();
    recordRefNode1.set("name", JsonNodeFactory.instance.textNode("R&D"));
    recordRefNode1.set("internalId", JsonNodeFactory.instance.textNode("12345"));
    recordRefNode1.set("externalId", JsonNodeFactory.instance.nullNode());
    recordRefNode1.set("type", JsonNodeFactory.instance.nullNode());
    String recordRefJson1 = objectMapper.writer().writeValueAsString(recordRef1);
    FieldDesc fieldDesc = typeDesc.getField("department");
    AvroConverter<RecordRef, String> converter1 = (AvroConverter<RecordRef, String>) transducer.getValueConverter(fieldDesc);
    String testRecordRefJson1 = converter1.convertToAvro(recordRef1);
    assertNotNull(testRecordRefJson1);
    JsonNode testRecordRefNode1 = objectMapper.reader().readTree(testRecordRefJson1);
    assertTrue(testRecordRefNode1.has("name"));
    assertTrue(testRecordRefNode1.has("internalId"));
    assertTrue(testRecordRefNode1.has("externalId"));
    assertTrue(testRecordRefNode1.has("type"));
    assertEquals(recordRef1.getName(), testRecordRefNode1.get("name").asText());
    assertEquals(recordRef1.getInternalId(), testRecordRefNode1.get("internalId").asText());
    assertEquals(recordRef1.getExternalId(), testRecordRefNode1.get("externalId").asText(null));
    assertNull(testRecordRefNode1.get("type").asText(null));
    RecordRef testRecordRef1 = converter1.convertToDatum(recordRefJson1);
    assertNotNull(testRecordRef1);
    assertEquals(recordRef1.getName(), testRecordRef1.getName());
    assertEquals(recordRef1.getInternalId(), testRecordRef1.getInternalId());
    assertEquals(recordRef1.getExternalId(), testRecordRef1.getExternalId());
    assertEquals(recordRef1.getType(), testRecordRef1.getType());
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) RecordRef(com.netsuite.webservices.test.platform.core.RecordRef) NsObjectInputTransducer(org.talend.components.netsuite.input.NsObjectInputTransducer) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AvroConverter(org.talend.daikon.avro.converter.AvroConverter) FieldDesc(org.talend.components.netsuite.client.model.FieldDesc) Test(org.junit.Test)

Example 8 with RecordRef

use of com.netsuite.webservices.test.platform.core.RecordRef in project components by Talend.

the class NetSuiteClientServiceTest method testDeleteList.

@Test
public void testDeleteList() throws Exception {
    TypeDesc typeDesc = clientService.getMetaDataSource().getTypeInfo("RecordRef");
    List<RecordRef> recordRefList = makeNsObjects(new NsObjectComposer<RecordRef>(clientService.getMetaDataSource(), typeDesc), 10);
    DeleteListResponse response = new DeleteListResponse();
    response.setWriteResponseList(createSuccessWriteResponseList(recordRefList.size()));
    when(port.deleteList(notNull(DeleteListRequest.class))).thenReturn(response);
    clientService.deleteList(recordRefList);
    verify(port, times(1)).login(notNull(LoginRequest.class));
    verify(port, times(1)).deleteList(notNull(DeleteListRequest.class));
    List<NsWriteResponse<RecordRef>> writeResponses = clientService.deleteList(null);
    assertTrue(writeResponses.isEmpty());
}
Also used : DeleteListRequest(com.netsuite.webservices.test.platform.messages.DeleteListRequest) DeleteListResponse(com.netsuite.webservices.test.platform.messages.DeleteListResponse) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) RecordRef(com.netsuite.webservices.test.platform.core.RecordRef) LoginRequest(com.netsuite.webservices.test.platform.messages.LoginRequest) Test(org.junit.Test)

Example 9 with RecordRef

use of com.netsuite.webservices.test.platform.core.RecordRef in project components by Talend.

the class NetSuiteClientServiceTest method testGet.

@Test
public void testGet() throws Exception {
    TypeDesc typeDesc = clientService.getMetaDataSource().getTypeInfo("PurchaseOrder");
    TypeDesc refTypeDesc = clientService.getMetaDataSource().getTypeInfo("RecordRef");
    PurchaseOrder record = new NsObjectComposer<PurchaseOrder>(clientService.getMetaDataSource(), typeDesc).composeObject();
    RecordRef recordRef = new NsObjectComposer<RecordRef>(clientService.getMetaDataSource(), refTypeDesc).composeObject();
    GetResponse response = new GetResponse();
    response.setReadResponse(createSuccessReadResponse(record));
    when(port.get(notNull(GetRequest.class))).thenReturn(response);
    clientService.get(recordRef);
    verify(port, times(1)).login(notNull(LoginRequest.class));
    verify(port, times(1)).get(notNull(GetRequest.class));
    NsReadResponse readResponse = clientService.get(null);
    assertNull(readResponse.getStatus());
    assertNull(readResponse.getRecord());
}
Also used : GetRequest(com.netsuite.webservices.test.platform.messages.GetRequest) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) RecordRef(com.netsuite.webservices.test.platform.core.RecordRef) PurchaseOrder(com.netsuite.webservices.test.transactions.purchases.PurchaseOrder) LoginRequest(com.netsuite.webservices.test.platform.messages.LoginRequest) GetResponse(com.netsuite.webservices.test.platform.messages.GetResponse) Test(org.junit.Test)

Example 10 with RecordRef

use of com.netsuite.webservices.test.platform.core.RecordRef in project components by Talend.

the class NetSuiteClientServiceTest method testRetrying.

@Test
public void testRetrying() throws Exception {
    clientService.setRetryCount(3);
    clientService.setRetryInterval(1);
    clientService.login();
    TypeDesc typeDesc = clientService.getMetaDataSource().getTypeInfo("RecordRef");
    RecordRef recordRef = new NsObjectComposer<RecordRef>(clientService.getMetaDataSource(), typeDesc).composeObject();
    final DeleteResponse response = new DeleteResponse();
    response.setWriteResponse(createSuccessWriteResponse());
    final AtomicInteger counter = new AtomicInteger(3);
    when(port.delete(notNull(DeleteRequest.class))).thenAnswer(new Answer<DeleteResponse>() {

        @Override
        public DeleteResponse answer(InvocationOnMock invocation) throws Throwable {
            if (counter.decrementAndGet() > 0) {
                com.netsuite.webservices.test.platform.faults.InvalidSessionFault faultInfo = new com.netsuite.webservices.test.platform.faults.InvalidSessionFault();
                faultInfo.setCode(FaultCodeType.SESSION_TIMED_OUT);
                faultInfo.setMessage("Session timed out");
                InvalidSessionFault fault = new InvalidSessionFault(faultInfo.getMessage(), faultInfo);
                throw fault;
            }
            return response;
        }
    });
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    clientService.delete(recordRef);
    stopWatch.stop();
    verify(port, times(3)).login(notNull(LoginRequest.class));
    verify(port, times(3)).delete(notNull(DeleteRequest.class));
    assertTrue(stopWatch.getTime() >= 3 * clientService.getRetryInterval() * 1000);
}
Also used : TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) RecordRef(com.netsuite.webservices.test.platform.core.RecordRef) InvalidSessionFault(com.netsuite.webservices.test.platform.InvalidSessionFault) LoginRequest(com.netsuite.webservices.test.platform.messages.LoginRequest) StopWatch(org.apache.commons.lang3.time.StopWatch) DeleteResponse(com.netsuite.webservices.test.platform.messages.DeleteResponse) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DeleteRequest(com.netsuite.webservices.test.platform.messages.DeleteRequest) Test(org.junit.Test)

Aggregations

RecordRef (com.netsuite.webservices.test.platform.core.RecordRef)13 Test (org.junit.Test)11 TypeDesc (org.talend.components.netsuite.client.model.TypeDesc)7 LoginRequest (com.netsuite.webservices.test.platform.messages.LoginRequest)6 DeleteRequest (com.netsuite.webservices.test.platform.messages.DeleteRequest)3 DeleteResponse (com.netsuite.webservices.test.platform.messages.DeleteResponse)3 NsObjectInputTransducer (org.talend.components.netsuite.input.NsObjectInputTransducer)3 AvroConverter (org.talend.daikon.avro.converter.AvroConverter)3 CustomRecordRef (com.netsuite.webservices.test.platform.core.CustomRecordRef)2 Passport (com.netsuite.webservices.test.platform.core.Passport)2 PurchaseOrder (com.netsuite.webservices.test.transactions.purchases.PurchaseOrder)2 FieldDesc (org.talend.components.netsuite.client.model.FieldDesc)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Account (com.netsuite.webservices.test.lists.accounting.Account)1 InvalidSessionFault (com.netsuite.webservices.test.platform.InvalidSessionFault)1 BooleanCustomFieldRef (com.netsuite.webservices.test.platform.core.BooleanCustomFieldRef)1 CustomFieldList (com.netsuite.webservices.test.platform.core.CustomFieldList)1 RecordRefList (com.netsuite.webservices.test.platform.core.RecordRefList)1