Search in sources :

Example 1 with AssertMatcher

use of org.talend.components.netsuite.test.AssertMatcher in project components by Talend.

the class NetSuiteClientServiceTest method testConnectAndLogin.

/**
 */
@Test
public void testConnectAndLogin() throws Exception {
    final NetSuiteCredentials credentials = webServiceMockTestFixture.getCredentials();
    final NetSuitePortType port = webServiceMockTestFixture.getPortMock();
    SessionResponse sessionResponse = new SessionResponse();
    sessionResponse.setStatus(createSuccessStatus());
    LoginResponse response = new LoginResponse();
    response.setSessionResponse(sessionResponse);
    when(port.login(argThat(new AssertMatcher<LoginRequest>() {

        @Override
        protected void doAssert(LoginRequest target) throws Exception {
            assertEquals(credentials.getEmail(), target.getPassport().getEmail());
            assertEquals(credentials.getPassword(), target.getPassport().getPassword());
            assertEquals(credentials.getRoleId(), target.getPassport().getRole().getInternalId());
            assertEquals(credentials.getAccount(), target.getPassport().getAccount());
            MessageContext messageContext = MessageContextHolder.get();
            assertNotNull(messageContext);
            List<Header> headers = (List<Header>) messageContext.get(Header.HEADER_LIST);
            assertNotNull(headers);
            Header appInfoHeader = NetSuiteWebServiceMockTestFixture.getHeader(headers, new QName(NetSuiteClientServiceImpl.NS_URI_PLATFORM_MESSAGES, "applicationInfo"));
            assertNotNull(appInfoHeader);
        }
    }))).thenReturn(response);
    NetSuiteClientService<?> clientService = webServiceMockTestFixture.getClientService();
    clientService.login();
    verify(port, times(1)).login(any(LoginRequest.class));
}
Also used : NetSuitePortType(com.netsuite.webservices.v2016_2.platform.NetSuitePortType) NetSuiteCredentials(org.talend.components.netsuite.client.NetSuiteCredentials) LoginResponse(com.netsuite.webservices.v2016_2.platform.messages.LoginResponse) Header(org.apache.cxf.headers.Header) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) List(java.util.List) LoginRequest(com.netsuite.webservices.v2016_2.platform.messages.LoginRequest) MessageContext(javax.xml.ws.handler.MessageContext) SessionResponse(com.netsuite.webservices.v2016_2.platform.messages.SessionResponse) AssertMatcher(org.talend.components.netsuite.test.AssertMatcher) Test(org.junit.Test)

Example 2 with AssertMatcher

use of org.talend.components.netsuite.test.AssertMatcher in project components by Talend.

the class NetSuiteClientServiceTest method testLogin.

@Test
public void testLogin() throws Exception {
    clientService.login();
    verify(port, times(1)).login(argThat(new AssertMatcher<LoginRequest>() {

        @Override
        protected void doAssert(LoginRequest request) throws Exception {
            assertNotNull(request);
            Passport passport = request.getPassport();
            assertNotNull(passport);
        }
    }));
    // Verify that logging in not performed for already logged in client
    TypeDesc typeDesc = clientService.getMetaDataSource().getTypeInfo("RecordRef");
    RecordRef recordRef = new NsObjectComposer<RecordRef>(clientService.getMetaDataSource(), typeDesc).composeObject();
    DeleteResponse response = new DeleteResponse();
    response.setWriteResponse(createSuccessWriteResponse());
    when(port.delete(notNull(DeleteRequest.class))).thenReturn(response);
    clientService.delete(recordRef);
    verify(port, times(1)).login(any(LoginRequest.class));
}
Also used : Passport(com.netsuite.webservices.test.platform.core.Passport) DeleteResponse(com.netsuite.webservices.test.platform.messages.DeleteResponse) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) RecordRef(com.netsuite.webservices.test.platform.core.RecordRef) LoginRequest(com.netsuite.webservices.test.platform.messages.LoginRequest) AssertMatcher(org.talend.components.netsuite.test.AssertMatcher) DeleteRequest(com.netsuite.webservices.test.platform.messages.DeleteRequest) Test(org.junit.Test)

Example 3 with AssertMatcher

use of org.talend.components.netsuite.test.AssertMatcher in project components by Talend.

the class NetSuiteClientServiceTest method testConnectAndLogin.

/**
 * TODO Verify headers (applicationInfo etc.)
 */
@Test
public void testConnectAndLogin() throws Exception {
    final NetSuiteCredentials credentials = webServiceMockTestFixture.getCredentials();
    final NetSuitePortType port = webServiceMockTestFixture.getPortMock();
    SessionResponse sessionResponse = new SessionResponse();
    sessionResponse.setStatus(createSuccessStatus());
    LoginResponse response = new LoginResponse();
    response.setSessionResponse(sessionResponse);
    when(port.login(argThat(new AssertMatcher<LoginRequest>() {

        @Override
        protected void doAssert(LoginRequest target) throws Exception {
            assertEquals(credentials.getEmail(), target.getPassport().getEmail());
            assertEquals(credentials.getPassword(), target.getPassport().getPassword());
            assertEquals(credentials.getRoleId(), target.getPassport().getRole().getInternalId());
            assertEquals(credentials.getAccount(), target.getPassport().getAccount());
            MessageContext messageContext = MessageContextHolder.get();
            assertNotNull(messageContext);
            List<Header> headers = (List<Header>) messageContext.get(Header.HEADER_LIST);
            assertNotNull(headers);
            Header appInfoHeader = NetSuiteWebServiceMockTestFixture.getHeader(headers, new QName(NetSuiteClientServiceImpl.NS_URI_PLATFORM_MESSAGES, "applicationInfo"));
            assertNotNull(appInfoHeader);
        }
    }))).thenReturn(response);
    NetSuiteClientService<?> clientService = webServiceMockTestFixture.getClientService();
    clientService.login();
    verify(port, times(1)).login(any(LoginRequest.class));
}
Also used : NetSuitePortType(com.netsuite.webservices.v2014_2.platform.NetSuitePortType) NetSuiteCredentials(org.talend.components.netsuite.client.NetSuiteCredentials) LoginResponse(com.netsuite.webservices.v2014_2.platform.messages.LoginResponse) Header(org.apache.cxf.headers.Header) QName(javax.xml.namespace.QName) List(java.util.List) LoginRequest(com.netsuite.webservices.v2014_2.platform.messages.LoginRequest) MessageContext(javax.xml.ws.handler.MessageContext) SessionResponse(com.netsuite.webservices.v2014_2.platform.messages.SessionResponse) AssertMatcher(org.talend.components.netsuite.test.AssertMatcher) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 AssertMatcher (org.talend.components.netsuite.test.AssertMatcher)3 List (java.util.List)2 QName (javax.xml.namespace.QName)2 MessageContext (javax.xml.ws.handler.MessageContext)2 Header (org.apache.cxf.headers.Header)2 NetSuiteCredentials (org.talend.components.netsuite.client.NetSuiteCredentials)2 Passport (com.netsuite.webservices.test.platform.core.Passport)1 RecordRef (com.netsuite.webservices.test.platform.core.RecordRef)1 DeleteRequest (com.netsuite.webservices.test.platform.messages.DeleteRequest)1 DeleteResponse (com.netsuite.webservices.test.platform.messages.DeleteResponse)1 LoginRequest (com.netsuite.webservices.test.platform.messages.LoginRequest)1 NetSuitePortType (com.netsuite.webservices.v2014_2.platform.NetSuitePortType)1 LoginRequest (com.netsuite.webservices.v2014_2.platform.messages.LoginRequest)1 LoginResponse (com.netsuite.webservices.v2014_2.platform.messages.LoginResponse)1 SessionResponse (com.netsuite.webservices.v2014_2.platform.messages.SessionResponse)1 NetSuitePortType (com.netsuite.webservices.v2016_2.platform.NetSuitePortType)1 LoginRequest (com.netsuite.webservices.v2016_2.platform.messages.LoginRequest)1 LoginResponse (com.netsuite.webservices.v2016_2.platform.messages.LoginResponse)1 SessionResponse (com.netsuite.webservices.v2016_2.platform.messages.SessionResponse)1