UNOMI-118 : Basic test, profile import
Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/a4ecc1ee Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/a4ecc1ee Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/a4ecc1ee Branch: refs/heads/master Commit: a4ecc1ee1e88728306f0b93f64ca0ff7ecff104d Parents: 05544a7 Author: Abdelkader Midani <amid...@apache.org> Authored: Tue Aug 8 14:46:47 2017 +0200 Committer: Abdelkader Midani <amid...@apache.org> Committed: Tue Aug 8 14:46:47 2017 +0200 ---------------------------------------------------------------------- .gitignore | 2 +- itests/pom.xml | 7 ++ .../java/org/apache/unomi/itests/AllITs.java | 3 +- .../java/org/apache/unomi/itests/BaseIT.java | 18 +++- .../apache/unomi/itests/ProfileImportIT.java | 107 +++++++++++++++++++ itests/src/test/resources/1-basic-test.csv | 3 + .../test/resources/org.apache.unomi.router.cfg | 43 ++++++++ pom.xml | 2 + 8 files changed, 181 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/a4ecc1ee/.gitignore ---------------------------------------------------------------------- diff --git a/.gitignore b/.gitignore index c3e5009..134bd4c 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ target .project /src/main/webapp/META-INF/MANIFEST.MF -/.idea +/**/.idea *.iml .DS_Store /performance-tests/.cache http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/a4ecc1ee/itests/pom.xml ---------------------------------------------------------------------- diff --git a/itests/pom.xml b/itests/pom.xml index 036cb1d..a5b4338 100644 --- a/itests/pom.xml +++ b/itests/pom.xml @@ -37,6 +37,13 @@ </dependency> <dependency> <groupId>org.apache.unomi</groupId> + <artifactId>unomi-router-karaf-feature</artifactId> + <classifier>features</classifier> + <version>${project.version}</version> + <type>xml</type> + </dependency> + <dependency> + <groupId>org.apache.unomi</groupId> <artifactId>unomi-persistence-spi</artifactId> <version>${project.version}</version> <scope>provided</scope> http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/a4ecc1ee/itests/src/test/java/org/apache/unomi/itests/AllITs.java ---------------------------------------------------------------------- diff --git a/itests/src/test/java/org/apache/unomi/itests/AllITs.java b/itests/src/test/java/org/apache/unomi/itests/AllITs.java index 96e5245..c2b6fd3 100644 --- a/itests/src/test/java/org/apache/unomi/itests/AllITs.java +++ b/itests/src/test/java/org/apache/unomi/itests/AllITs.java @@ -32,7 +32,8 @@ import org.junit.runners.Suite.SuiteClasses; ConditionEvaluatorIT.class, ConditionESQueryBuilderIT.class, SegmentIT.class, - ProfileServiceIT.class + ProfileServiceIT.class, + ProfileImportIT.class }) public class AllITs { } http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/a4ecc1ee/itests/src/test/java/org/apache/unomi/itests/BaseIT.java ---------------------------------------------------------------------- diff --git a/itests/src/test/java/org/apache/unomi/itests/BaseIT.java b/itests/src/test/java/org/apache/unomi/itests/BaseIT.java index cfb8ed3..fa56a74 100644 --- a/itests/src/test/java/org/apache/unomi/itests/BaseIT.java +++ b/itests/src/test/java/org/apache/unomi/itests/BaseIT.java @@ -19,6 +19,7 @@ package org.apache.unomi.itests; import org.ops4j.pax.exam.Configuration; import org.ops4j.pax.exam.Option; +import org.ops4j.pax.exam.karaf.options.KarafDistributionConfigurationFileReplacementOption; import org.ops4j.pax.exam.karaf.options.LogLevelOption.LogLevel; import org.ops4j.pax.exam.options.MavenArtifactUrlReference; import org.ops4j.pax.exam.options.MavenUrlReference; @@ -39,6 +40,8 @@ public abstract class BaseIT { protected static final String URL = "http://localhost:" + HTTP_PORT; + protected static final String KARAF_DIR = "target/exam"; + @Configuration public Option[] config() { MavenArtifactUrlReference karafUrl = maven() @@ -77,13 +80,23 @@ public abstract class BaseIT { .classifier("features") .type("xml") .versionAsInProject(); + MavenUrlReference routerRepo = maven() + .groupId("org.apache.unomi") + .artifactId("unomi-router-karaf-feature") + .classifier("features") + .type("xml") + .versionAsInProject(); return new Option[]{ debugConfiguration("5005", false), karafDistributionConfiguration() .frameworkUrl(karafUrl) - .unpackDirectory(new File("target/exam")) - .useDeployFolder(false), + .unpackDirectory(new File(KARAF_DIR)) + .useDeployFolder(true), + replaceConfigurationFile("etc/org.apache.unomi.router.cfg", new File( + "src/test/resources/org.apache.unomi.router.cfg")), + replaceConfigurationFile("data/tmp/unomi_oneshot_import_configs/1-basic-test.csv", new File( + "src/test/resources/1-basic-test.csv")), keepRuntimeFolder(), configureConsole().ignoreLocalConsole(), logLevel(LogLevel.INFO), @@ -96,6 +109,7 @@ public abstract class BaseIT { features(karafCxfRepo, "cxf"), features(karafCellarRepo, "cellar"), features(contextServerRepo, "unomi-kar"), + features(routerRepo, "unomi-router-karaf-feature"), // we need to wrap the HttpComponents libraries ourselves since the OSGi bundles provided by the project are incorrect wrappedBundle(mavenBundle("org.apache.httpcomponents", "httpcore").versionAsInProject()), http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/a4ecc1ee/itests/src/test/java/org/apache/unomi/itests/ProfileImportIT.java ---------------------------------------------------------------------- diff --git a/itests/src/test/java/org/apache/unomi/itests/ProfileImportIT.java b/itests/src/test/java/org/apache/unomi/itests/ProfileImportIT.java new file mode 100644 index 0000000..afd3ce9 --- /dev/null +++ b/itests/src/test/java/org/apache/unomi/itests/ProfileImportIT.java @@ -0,0 +1,107 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ +package org.apache.unomi.itests; + +import org.apache.unomi.api.PartialList; +import org.apache.unomi.api.Profile; +import org.apache.unomi.api.services.ProfileService; +import org.apache.unomi.router.api.ImportConfiguration; +import org.apache.unomi.router.api.RouterConstants; +import org.apache.unomi.router.api.services.ImportExportConfigurationService; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.ops4j.pax.exam.junit.PaxExam; +import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy; +import org.ops4j.pax.exam.spi.reactors.PerSuite; +import org.ops4j.pax.exam.util.Filter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.inject.Inject; +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Created by amidani on 03/08/2017. + */ +@RunWith(PaxExam.class) +@ExamReactorStrategy(PerSuite.class) +public class ProfileImportIT extends BaseIT { + + @Inject + @Filter("(configDiscriminator=IMPORT)") + protected ImportExportConfigurationService<ImportConfiguration> importConfigurationService; + @Inject + protected ProfileService profileService; + private Logger logger = LoggerFactory.getLogger(ProfileImportIT.class); + + @Before + public void setUp() { + + /*** Basic Test ***/ + ImportConfiguration importConfiguration = new ImportConfiguration(); + importConfiguration.setItemId("1-basic-test"); + importConfiguration.setConfigType(RouterConstants.IMPORT_EXPORT_CONFIG_TYPE_ONESHOT); + importConfiguration.setMergingProperty("email"); + importConfiguration.setOverwriteExistingProfiles(true); + + Map mapping = new HashMap(); + mapping.put("email", 0); + mapping.put("firstName", 1); + mapping.put("lastName", 2); + + importConfiguration.getProperties().put("mapping", mapping); + importConfiguration.setActive(true); + + importConfigurationService.save(importConfiguration); + + } + + @Test + public void testGetImportConfigList() { + List<ImportConfiguration> importConfigurations = importConfigurationService.getAll(); + Assert.assertEquals(1, importConfigurations.size()); + } + + @Test + public void testBasic() throws IOException, InterruptedException { + + //Wait for the csv to be processed + Thread.sleep(10000); + + //Check saved profiles + PartialList<Profile> profiles = profileService.findProfilesByPropertyValue("properties.email", "bas...@test.com", 0, 10, null); + logger.info("$$$$ : Profile count : " + profileService.getAllProfilesCount()); + logger.info("$$$$ : List size : " + profiles.getList().size()); + Assert.assertEquals(3, profileService.getAllProfilesCount()); + Assert.assertEquals(1, profiles.getList().size()); + Assert.assertNotNull(profiles.get(0)); + Assert.assertEquals("Basic1", profiles.get(0).getProperty("firstName")); + Assert.assertEquals("User1", profiles.get(0).getProperty("lastName")); + + //Check import config status + ImportConfiguration importConfiguration = importConfigurationService.load("1-basic-test"); + Assert.assertEquals(RouterConstants.CONFIG_STATUS_COMPLETE_SUCCESS, importConfiguration.getStatus()); + Assert.assertEquals(1, importConfiguration.getExecutions().size()); + + } + +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/a4ecc1ee/itests/src/test/resources/1-basic-test.csv ---------------------------------------------------------------------- diff --git a/itests/src/test/resources/1-basic-test.csv b/itests/src/test/resources/1-basic-test.csv new file mode 100644 index 0000000..337940f --- /dev/null +++ b/itests/src/test/resources/1-basic-test.csv @@ -0,0 +1,3 @@ +bas...@test.com,Basic1,User1 +bas...@test.com,Basic2,User2 +bas...@test.com,Basic3,User3 \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/a4ecc1ee/itests/src/test/resources/org.apache.unomi.router.cfg ---------------------------------------------------------------------- diff --git a/itests/src/test/resources/org.apache.unomi.router.cfg b/itests/src/test/resources/org.apache.unomi.router.cfg new file mode 100644 index 0000000..6d5f985 --- /dev/null +++ b/itests/src/test/resources/org.apache.unomi.router.cfg @@ -0,0 +1,43 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +#Configuration Type values {'nobroker', 'kafka'} +router.config.type=nobroker + +#Uncomment and update Kafka settings to use Kafka as a broker + +#Kafka +#kafka.host=localhost +#kafka.port=9092 +#kafka.import.topic=import-deposit +#kafka.export.topic=export-deposit +#kafka.import.groupId=unomi-import-group +#kafka.export.groupId=unomi-import-group +#kafka.consumerCount=10 +#kafka.autoCommit=true + +#Import One Shot upload directory +import.oneshot.uploadDir=${karaf.data}/tmp/unomi_oneshot_import_configs/ + +#Import/Export executions history size +executionsHistory.size=5 + +#errors report size +executions.error.report.size=200 + +#Allowed source endpoints +config.allowedEndpoints=file,ftp,sftp,ftps \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/a4ecc1ee/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 376cf21..3dd44f6 100644 --- a/pom.xml +++ b/pom.xml @@ -409,6 +409,8 @@ <exclude>**/org.ops4j.pax.exam.TestContainerFactory</exclude> <exclude>**/maven-metadata-local.xml</exclude> <exclude>**/src/test/resources/data/*.txt</exclude> + <!-- Test resources CSV --> + <exclude>**/src/test/resources/**/*.csv</exclude> <exclude>**/keystore</exclude> <!--manual resources --> <exclude>**/*.css</exclude>