Skip to content

Commit

Permalink
Design Time Validation for missing fields (new)
Browse files Browse the repository at this point in the history
  • Loading branch information
psainics committed Jan 6, 2025
1 parent 099952a commit 4a0211c
Showing 1 changed file with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import io.cdap.cdap.api.data.format.StructuredRecord;
import io.cdap.cdap.api.data.schema.Schema;
import io.cdap.cdap.api.plugin.PluginConfig;
import io.cdap.cdap.etl.api.FailureCollector;
import io.cdap.cdap.etl.api.batch.BatchSource;
import io.cdap.cdap.etl.api.batch.BatchSourceContext;
import io.cdap.cdap.etl.api.connector.BrowseDetail;
Expand Down Expand Up @@ -283,6 +285,62 @@ public void testSampleWithoutSampleData() throws IOException, TransportException
Assert.assertNull(sample);
}

@Test
public void testOAuthEnterTokenMissingFields() {
SuccessFactorsPluginConfig pluginConfig = new SuccessFactorsPluginConfig.Builder()
.referenceName("unit-test-ref-name")
.baseURL("http://localhost")
.entityName("entity-name")
.authType(SuccessFactorsConnectorConfig.OAUTH2)
.assertionTokenType(SuccessFactorsConnectorConfig.ENTER_TOKEN)
.setTokenURL("http://localhost/token")
.build();
ConnectorContext context = new MockConnectorContext(new MockConnectorConfigurer());
FailureCollector collector = context.getFailureCollector();
SuccessFactorsConnector connector = new SuccessFactorsConnector(pluginConfig.getConnection());
connector.test(context);
Assert.assertEquals(4, collector.getValidationFailures().size());
Assert.assertEquals("Required property 'clientId' is blank.", collector.getValidationFailures().get(0).getMessage());
Assert.assertEquals("Required property 'companyId' is blank.", collector.getValidationFailures().get(1).getMessage());
Assert.assertEquals("Required property 'assertionToken' is blank.", collector.getValidationFailures().get(2).getMessage());
Assert.assertEquals("Unable to call SuccessFactorsEntity", collector.getValidationFailures().get(3).getMessage());
}

@Test
public void testOAuthCreateTokenMissingFields() {
SuccessFactorsPluginConfig pluginConfig = new SuccessFactorsPluginConfig.Builder()
.referenceName("unit-test-ref-name")
.baseURL("http://localhost")
.entityName("entity-name")
.authType(SuccessFactorsConnectorConfig.OAUTH2)
.assertionTokenType(SuccessFactorsConnectorConfig.CREATE_TOKEN)
.setTokenURL("http://localhost/token")
.build();
ConnectorContext context = new MockConnectorContext(new MockConnectorConfigurer());
FailureCollector collector = context.getFailureCollector();
SuccessFactorsConnector connector = new SuccessFactorsConnector(pluginConfig.getConnection());
connector.test(context);
Assert.assertEquals(5, collector.getValidationFailures().size());
Assert.assertEquals("Required property 'clientId' is blank.", collector.getValidationFailures().get(0).getMessage());
Assert.assertEquals("Required property 'companyId' is blank.", collector.getValidationFailures().get(1).getMessage());
Assert.assertEquals("Required property 'privateKey' is blank.", collector.getValidationFailures().get(2).getMessage());
Assert.assertEquals("Required property 'userId' is blank.", collector.getValidationFailures().get(3).getMessage());
Assert.assertEquals("Unable to call SuccessFactorsEntity", collector.getValidationFailures().get(4).getMessage());
}

@Test
public void testDefaultValueForExpireTime() {
SuccessFactorsPluginConfig pluginConfig = new SuccessFactorsPluginConfig.Builder()
.referenceName("unit-test-ref-name")
.baseURL("http://localhost")
.entityName("entity-name")
.authType(SuccessFactorsConnectorConfig.OAUTH2)
.assertionTokenType(SuccessFactorsConnectorConfig.CREATE_TOKEN)
.setExpireInMinutes(null)
.build();
Assert.assertEquals(1440, pluginConfig.getConnection().getExpireInMinutes().intValue());
}

@Test
public void testSampleWithSampleData() throws IOException, TransportException, EntityProviderException,
SuccessFactorsServiceException, EdmException {
Expand Down

0 comments on commit 4a0211c

Please sign in to comment.