diff --git a/step-controller/step-controller-server-webapp/src/test/java/step/core/export/ExportManagerTest.java b/step-controller/step-controller-server-webapp/src/test/java/step/core/export/ExportManagerTest.java index 050443c77..5bb1fe26b 100644 --- a/step-controller/step-controller-server-webapp/src/test/java/step/core/export/ExportManagerTest.java +++ b/step-controller/step-controller-server-webapp/src/test/java/step/core/export/ExportManagerTest.java @@ -577,18 +577,28 @@ public void testExportPlanByWithCustomFields() throws Exception { testExportFile.delete(); } } - + @Test public void testExportPlanRecursively() throws Exception { - testExportPlansRecursively(true); + testExportPlansRecursively(false, true); } - + @Test public void testExportPlanRecursivelyNewReferences() throws Exception { - testExportPlansRecursively(false); + testExportPlansRecursively(false, false); } - - private void testExportPlansRecursively(boolean overwrite) throws Exception { + + @Test + public void testExportPlanRecursivelyWithPansOnly() throws Exception { + testExportPlansRecursively(true, true); + } + + @Test + public void testExportPlanRecursivelyNewReferencesWithPansOnly() throws Exception { + testExportPlansRecursively(true, false); + } + + private void testExportPlansRecursively(boolean plansOnly, boolean overwrite) throws Exception { Sequence rootSequence = sequence(); Plan plan = PlanBuilder.create().startBlock(rootSequence).add(sequence()).endBlock().build(); planAccessor.save(plan); @@ -603,27 +613,23 @@ private void testExportPlansRecursively(boolean overwrite) throws Exception { sequence.addChild(callFunction); Plan plan2 = PlanBuilder.create().startBlock(rootSequence).add(sequence).endBlock().build(); planAccessor.save(plan2); - + File testExportFile = new File("testExport.json"); try (FileOutputStream outputStream = new FileOutputStream(testExportFile)) { ExportManager exportManager = newExportManager(); Map metadata = buildMetadata(); ExportConfiguration exportConfig = new ExportConfiguration(outputStream, metadata, dummyObjectPredicate(), "plans", true, null); exportManager.exportById(exportConfig, plan2.getId().toString()); - - planAccessor.getAll().forEachRemaining(p->planAccessor.remove(p.getId())); - functionAccessor.getAll().forEachRemaining(p->functionAccessor.remove(p.getId())); - + + planAccessor.getAll().forEachRemaining(p -> planAccessor.remove(p.getId())); + functionAccessor.getAll().forEachRemaining(p -> functionAccessor.remove(p.getId())); + ImportManager importManager = createNewContextAndGetImportManager(); - importManager.importAll(new ImportConfiguration(testExportFile, dummyObjectEnricher(), null, overwrite)); - - AtomicInteger nbPlans = new AtomicInteger(0); - planAccessor.getAll().forEachRemaining(p-> nbPlans.incrementAndGet()); - AtomicInteger nbFunctions = new AtomicInteger(0); - functionAccessor.getAll().forEachRemaining(f->nbFunctions.incrementAndGet()); - assertEquals(2, nbPlans.intValue()); - assertEquals(1, nbFunctions.intValue()); - + importManager.importAll(new ImportConfiguration(testExportFile, dummyObjectEnricher(), plansOnly ? List.of("plans") : null, overwrite)); + + assertEquals(2, planAccessor.stream().count()); + assertEquals(plansOnly ? 0 : 1, functionAccessor.stream().count()); + Plan actualPlan = planAccessor.get(plan.getId()); Plan actualPlan2 = planAccessor.get(plan2.getId()); Function actualFunction = functionAccessor.get(function.getId()); @@ -631,7 +637,11 @@ private void testExportPlansRecursively(boolean overwrite) throws Exception { assertEquals(plan.getId(), actualPlan.getId()); assertEquals(plan.getRoot(), actualPlan.getRoot()); assertEquals(plan2.getId(), actualPlan2.getId()); - assertEquals(function.getId(), actualFunction.getId()); + if (plansOnly) { + assertNull(actualFunction); + } else { + assertEquals(function.getId(), actualFunction.getId()); + } } else { assertNull(actualPlan); assertNull(actualPlan2); @@ -641,7 +651,7 @@ private void testExportPlansRecursively(boolean overwrite) throws Exception { testExportFile.delete(); } } - + @Test public void testExportPlansWithCompo() throws Exception { testExportPlansWithCompoFct(true); diff --git a/step-core/src/main/java/step/core/imports/ImportManager.java b/step-core/src/main/java/step/core/imports/ImportManager.java index 287bc0fde..61884088c 100644 --- a/step-core/src/main/java/step/core/imports/ImportManager.java +++ b/step-core/src/main/java/step/core/imports/ImportManager.java @@ -175,25 +175,26 @@ private String importEntitiesToTemporaryCollection(ImportConfiguration importCon FilesystemCollectionFactory tempCollectionFactory = importContext.getTempCollectionFactory(); Collection tempCollection = tempCollectionFactory.getCollection(name, Document.class); - if (!skip) { - if (entityByName == null) { - throw new RuntimeException( - "The entity type with name '" + name + "' is unsupported in this version or license of step."); + if (entityByName == null) { + throw new RuntimeException( + "The entity type with name '" + name + "' is unsupported in this version or license of step."); + } + if (jParser.nextToken().equals(JsonToken.START_ARRAY)) { + if (!skip) { + logger.info("Importing entities of type " + name); } - logger.info("Importing entities of type " + name); - if (jParser.nextToken().equals(JsonToken.START_ARRAY)) { - while (!jParser.nextToken().equals(JsonToken.END_ARRAY)) { + while (!jParser.nextToken().equals(JsonToken.END_ARRAY)) { + if (!skip) { importOne(tempCollection, jParser); + } else { + // consume the json object when skipped + mapper.readValue(jParser, Document.class); } - } else { - throw new RuntimeException("A JSON array was expected for entity '" + name + "'"); } } else { - // consume the json object when skipped - // TODO: fix this - // mapper.readValue(jParser, BasicDBObject.class); + throw new RuntimeException("A JSON array was expected for entity '" + name + "'"); } - + return name; }