From 4a0211c39504ba7bbf27492bf4472960ee6e96e4 Mon Sep 17 00:00:00 2001 From: psainics Date: Mon, 6 Jan 2025 17:02:59 +0530 Subject: [PATCH] Design Time Validation for missing fields (new) --- .../SuccessFactorsConnectorTest.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/test/java/io/cdap/plugin/successfactors/connector/SuccessFactorsConnectorTest.java b/src/test/java/io/cdap/plugin/successfactors/connector/SuccessFactorsConnectorTest.java index b20cc33..e8c2da4 100644 --- a/src/test/java/io/cdap/plugin/successfactors/connector/SuccessFactorsConnectorTest.java +++ b/src/test/java/io/cdap/plugin/successfactors/connector/SuccessFactorsConnectorTest.java @@ -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; @@ -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 {