use of org.talend.components.netsuite.input.NetSuiteInputProperties in project components by Talend.
the class NetSuiteSearchInputReaderIT method testInput.
@Test
public void testInput() throws Exception {
RuntimeContainer container = mock(RuntimeContainer.class);
NetSuiteInputProperties properties = new NetSuiteInputProperties("test");
properties.init();
properties.connection.endpoint.setValue(webServiceTestFixture.getEndpointUrl());
properties.connection.email.setValue(webServiceTestFixture.getCredentials().getEmail());
properties.connection.password.setValue(webServiceTestFixture.getCredentials().getPassword());
properties.connection.account.setValue(webServiceTestFixture.getCredentials().getAccount());
properties.connection.role.setValue(Integer.valueOf(webServiceTestFixture.getCredentials().getRoleId()));
properties.connection.applicationId.setValue(webServiceTestFixture.getCredentials().getApplicationId());
properties.module.moduleName.setValue("Account");
NetSuiteRuntimeImpl runtime = new NetSuiteRuntimeImpl();
NetSuiteDatasetRuntime dataSetRuntime = runtime.getDatasetRuntime(properties.getConnectionProperties());
Schema schema = dataSetRuntime.getSchema(properties.module.moduleName.getValue());
properties.module.main.schema.setValue(schema);
properties.module.afterModuleName();
properties.module.searchQuery.field.setValue(Arrays.asList("Type"));
properties.module.searchQuery.operator.setValue(Arrays.asList("List.anyOf"));
properties.module.searchQuery.value1.setValue(Arrays.<Object>asList("Bank"));
properties.module.searchQuery.value2.setValue(Arrays.<Object>asList((String) null));
NetSuiteSource source = new NetSuiteSourceImpl();
source.initialize(container, properties);
NetSuiteSearchInputReader reader = (NetSuiteSearchInputReader) source.createReader(container);
boolean started = reader.start();
assertTrue(started);
IndexedRecord record = reader.getCurrent();
assertNotNull(record);
List<Schema.Field> fields = record.getSchema().getFields();
for (int i = 0; i < fields.size(); i++) {
Schema.Field typeField = getFieldByName(fields, "AcctType");
Object value = record.get(typeField.pos());
assertNotNull(value);
assertEquals(AccountType.BANK.value(), value);
}
}
use of org.talend.components.netsuite.input.NetSuiteInputProperties in project components by Talend.
the class NetSuiteSearchInputReaderTest method setUp.
@Override
@Before
public void setUp() throws Exception {
installMockTestFixture();
super.setUp();
properties = new NetSuiteInputProperties("test");
properties.init();
properties.connection.copyValuesFrom(mockTestFixture.getConnectionProperties());
}
use of org.talend.components.netsuite.input.NetSuiteInputProperties in project components by Talend.
the class NetSuiteEndpoint method createConnectionConfig.
/**
* Create connection configuration for given connection properties.
*
* @param properties connection properties
* @return connection configuration
* @throws NetSuiteException if connection configuration not valid
*/
public static ConnectionConfig createConnectionConfig(NetSuiteProvideConnectionProperties properties) throws NetSuiteException {
NetSuiteConnectionProperties connProps = properties.getConnectionProperties();
if (StringUtils.isEmpty(connProps.endpoint.getStringValue())) {
throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.endpointUrlRequired"));
}
if (StringUtils.isEmpty(connProps.apiVersion.getStringValue())) {
throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.apiVersionRequired"));
}
if (StringUtils.isEmpty(connProps.email.getStringValue())) {
throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.emailRequired"));
}
if (StringUtils.isEmpty(connProps.password.getStringValue())) {
throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.passwordRequired"));
}
if (StringUtils.isEmpty(connProps.account.getStringValue())) {
throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.accountRequired"));
}
if (connProps.role.getValue() == null) {
throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.roleRequired"));
}
String endpointUrl = connProps.endpoint.getStringValue();
NetSuiteVersion endpointApiVersion;
try {
endpointApiVersion = NetSuiteVersion.detectVersion(endpointUrl);
} catch (IllegalArgumentException e) {
throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.couldNotDetectApiVersionFromEndpointUrl", endpointUrl));
}
String apiVersionString = connProps.apiVersion.getStringValue();
NetSuiteVersion apiVersion;
try {
apiVersion = NetSuiteVersion.parseVersion(apiVersionString);
} catch (IllegalArgumentException e) {
throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.invalidApiVersion", apiVersionString));
}
if (!endpointApiVersion.isSameMajor(apiVersion)) {
throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.endpointUrlApiVersionMismatch", endpointUrl, apiVersionString));
}
if (apiVersion.getMajorYear() >= 2015 && StringUtils.isEmpty(connProps.applicationId.getStringValue())) {
throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.applicationIdRequired"));
}
String email = connProps.email.getStringValue();
String password = connProps.password.getStringValue();
Integer roleId = connProps.role.getValue();
String account = connProps.account.getStringValue();
String applicationId = connProps.applicationId.getStringValue();
Boolean customizationEnabled = connProps.customizationEnabled.getValue();
NetSuiteCredentials credentials = new NetSuiteCredentials();
credentials.setEmail(email);
credentials.setPassword(password);
credentials.setRoleId(roleId.toString());
credentials.setAccount(account);
credentials.setApplicationId(applicationId);
try {
ConnectionConfig connectionConfig = new ConnectionConfig(new URL(endpointUrl), apiVersion.getMajor(), credentials);
if (properties instanceof NetSuiteInputProperties) {
connectionConfig.setBodyFieldsOnly(((NetSuiteInputProperties) properties).bodyFieldsOnly.getValue());
}
connectionConfig.setCustomizationEnabled(customizationEnabled);
return connectionConfig;
} catch (MalformedURLException e) {
throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.invalidEndpointUrl", endpointUrl));
}
}
use of org.talend.components.netsuite.input.NetSuiteInputProperties in project components by Talend.
the class NetSuiteSearchInputReaderTest method setUp.
@Override
@Before
public void setUp() throws Exception {
installMockTestFixture();
super.setUp();
properties = new NetSuiteInputProperties("test");
properties.init();
properties.connection.copyValuesFrom(mockTestFixture.getConnectionProperties());
}
use of org.talend.components.netsuite.input.NetSuiteInputProperties in project components by Talend.
the class NetSuiteSearchInputReaderIT method testSearch.
@Test
public void testSearch() throws Exception {
RuntimeContainer container = mock(RuntimeContainer.class);
NetSuiteInputProperties properties = new NetSuiteInputProperties("test");
properties.init();
properties.connection.endpoint.setValue(webServiceTestFixture.getEndpointUrl());
properties.connection.email.setValue(webServiceTestFixture.getCredentials().getEmail());
properties.connection.password.setValue(webServiceTestFixture.getCredentials().getPassword());
properties.connection.account.setValue(webServiceTestFixture.getCredentials().getAccount());
properties.connection.role.setValue(Integer.valueOf(webServiceTestFixture.getCredentials().getRoleId()));
properties.connection.applicationId.setValue(webServiceTestFixture.getCredentials().getApplicationId());
properties.module.moduleName.setValue("Account");
NetSuiteRuntimeImpl runtime = new NetSuiteRuntimeImpl();
runtime.setClientFactory(clientFactory);
NetSuiteDatasetRuntime dataSetRuntime = runtime.getDatasetRuntime(properties.getConnectionProperties());
Schema schema = dataSetRuntime.getSchema(properties.module.moduleName.getValue());
properties.module.main.schema.setValue(schema);
properties.module.afterModuleName();
properties.module.searchQuery.field.setValue(Arrays.asList("Type"));
properties.module.searchQuery.operator.setValue(Arrays.asList("List.anyOf"));
properties.module.searchQuery.value1.setValue(Arrays.<Object>asList("Bank"));
properties.module.searchQuery.value2.setValue(Arrays.<Object>asList((String) null));
NetSuiteSource source = new NetSuiteSourceImpl();
source.initialize(container, properties);
NetSuiteSearchInputReader reader = (NetSuiteSearchInputReader) source.createReader(container);
boolean started = reader.start();
assertTrue(started);
IndexedRecord record = reader.getCurrent();
assertNotNull(record);
List<Schema.Field> fields = record.getSchema().getFields();
for (int i = 0; i < fields.size(); i++) {
Schema.Field typeField = getFieldByName(fields, "AcctType");
Object value = record.get(typeField.pos());
assertNotNull(value);
assertEquals(AccountType.BANK.value(), value);
}
}
Aggregations