|
23 | 23 | import com.dotcms.contenttype.model.type.BaseContentType; |
24 | 24 | import com.dotcms.contenttype.model.type.ContentType; |
25 | 25 | import com.dotcms.contenttype.transform.contenttype.StructureTransformer; |
26 | | -import com.dotcms.datagen.ContentTypeDataGen; |
27 | | -import com.dotcms.datagen.ContentletDataGen; |
28 | | -import com.dotcms.datagen.FieldDataGen; |
29 | | -import com.dotcms.datagen.FolderDataGen; |
30 | | -import com.dotcms.datagen.SiteDataGen; |
31 | | -import com.dotcms.datagen.TemplateDataGen; |
32 | | -import com.dotcms.datagen.TestDataUtils; |
33 | | -import com.dotcms.datagen.TestUserUtils; |
| 26 | +import com.dotcms.datagen.*; |
34 | 27 | import com.dotcms.mock.request.MockAttributeRequest; |
35 | 28 | import com.dotcms.mock.request.MockHeaderRequest; |
36 | 29 | import com.dotcms.mock.request.MockHttpRequestIntegrationTest; |
37 | 30 | import com.dotcms.mock.request.MockSessionRequest; |
38 | 31 | import com.dotcms.repackage.com.csvreader.CsvReader; |
39 | 32 | import com.dotcms.uuid.shorty.ShortyIdAPI; |
| 33 | +import com.dotcms.variant.VariantAPI; |
40 | 34 | import com.dotmarketing.beans.Host; |
41 | 35 | import com.dotmarketing.beans.Identifier; |
42 | 36 | import com.dotmarketing.beans.Permission; |
@@ -2691,6 +2685,94 @@ public void importFile_importBinaryFieldUsingURLWithRequiredBinaryField_success( |
2691 | 2685 | } |
2692 | 2686 | } |
2693 | 2687 | } |
| 2688 | + /** |
| 2689 | + * Method to test: This test tries the {@link ImportUtil#importFile} |
| 2690 | + * Given Scenario: A parent content type related to a child content type that has two versions in two different languages |
| 2691 | + * ExpectedResult: The importer should return without errors, so content will be ready to be imported. |
| 2692 | + */ |
| 2693 | + @Test |
| 2694 | + public void importPreviewRelationshipLanguageTest() throws DotDataException, DotSecurityException, IOException { |
| 2695 | + //Creates content types |
| 2696 | + ContentType parentContentType = null; |
| 2697 | + ContentType childContentType = null; |
| 2698 | + |
| 2699 | + HashMap<String, List<String>> results; |
| 2700 | + CsvReader csvreader; |
| 2701 | + Reader reader; |
| 2702 | + String[] csvHeaders; |
| 2703 | + final int cardinality = RELATIONSHIP_CARDINALITY.ONE_TO_MANY.ordinal(); |
| 2704 | + |
| 2705 | + final Language language_1 = new LanguageDataGen().nextPersisted(); |
| 2706 | + final Language language_2 = new LanguageDataGen().nextPersisted(); |
| 2707 | + |
| 2708 | + try { |
| 2709 | + final Relationship relationship; |
| 2710 | + parentContentType = createTestContentType("parentContentType", "parentContentType" + new Date().getTime()); |
| 2711 | + childContentType = createTestContentType("childContentType", "childContentType" + new Date().getTime()); |
| 2712 | + |
| 2713 | + |
| 2714 | + com.dotcms.contenttype.model.field.Field field = FieldBuilder.builder(RelationshipField.class).name("testRelationship") |
| 2715 | + .variable("testRelationship") |
| 2716 | + .contentTypeId(parentContentType.id()).values(String.valueOf(cardinality)) |
| 2717 | + .relationType(childContentType.variable()).build(); |
| 2718 | + |
| 2719 | + field = fieldAPI.save(field, user); |
| 2720 | + relationship = relationshipAPI.byTypeValue( |
| 2721 | + parentContentType.variable() + StringPool.PERIOD + field.variable()); |
| 2722 | + |
| 2723 | + |
| 2724 | + //Creates child contentlet |
| 2725 | + final Contentlet childContentlet = new ContentletDataGen(childContentType.id()) |
| 2726 | + .languageId(language_1.getId()) |
| 2727 | + .setProperty(TITLE_FIELD_NAME, "child contentlet") |
| 2728 | + .setProperty(BODY_FIELD_NAME, "child contentlet").nextPersisted(); |
| 2729 | + |
| 2730 | + ContentletDataGen.createNewVersion(childContentlet, VariantAPI.DEFAULT_VARIANT, language_2, null); |
| 2731 | + |
| 2732 | + //Creates parent contentlet |
| 2733 | + Contentlet parentContentlet = new ContentletDataGen(parentContentType.id()) |
| 2734 | + .languageId(language_1.getId()) |
| 2735 | + .setProperty(TITLE_FIELD_NAME, "parent contentlet") |
| 2736 | + .setProperty(BODY_FIELD_NAME, "parent contentlet").next(); |
| 2737 | + |
| 2738 | + parentContentlet = contentletAPI.checkin(parentContentlet, |
| 2739 | + Map.of(relationship, list(childContentlet)), |
| 2740 | + user, false); |
| 2741 | + |
| 2742 | + reader = createTempFile( |
| 2743 | + "identifier, languageCode, countryCode, " + TITLE_FIELD_NAME + ", " + BODY_FIELD_NAME |
| 2744 | + + "\r\n" |
| 2745 | + + parentContentlet.getIdentifier() + ",en, US, Test1_edited, " + "\r\n" ); |
| 2746 | + csvreader = new CsvReader(reader); |
| 2747 | + csvreader.setSafetySwitch(false); |
| 2748 | + csvHeaders = csvreader.getHeaders(); |
| 2749 | + |
| 2750 | + int languageCodeHeaderColumn = 0; |
| 2751 | + int countryCodeHeaderColumn = 1; |
| 2752 | + |
| 2753 | + |
| 2754 | + results = ImportUtil.importFile(0L, defaultSite.getInode(), parentContentType.inode(), |
| 2755 | + new String[]{}, true, true, user, language_1.getId(), csvHeaders, |
| 2756 | + csvreader, languageCodeHeaderColumn, countryCodeHeaderColumn, reader, |
| 2757 | + schemeStepActionResult1.getAction().getId(),getHttpRequest()); |
| 2758 | + |
| 2759 | + validate(results, true, false, true); |
| 2760 | + |
| 2761 | + assertEquals(results.get("errors").size(), 0); |
| 2762 | + }finally { |
| 2763 | + try { |
| 2764 | + if (parentContentType != null) { |
| 2765 | + contentTypeApi.delete(parentContentType); |
| 2766 | + } |
| 2767 | + |
| 2768 | + if (childContentType != null) { |
| 2769 | + contentTypeApi.delete(childContentType); |
| 2770 | + } |
| 2771 | + } catch (Exception e) { |
| 2772 | + Logger.error("Error deleting content type", e); |
| 2773 | + } |
| 2774 | + } |
| 2775 | + } |
2694 | 2776 |
|
2695 | 2777 |
|
2696 | 2778 | /** |
|
0 commit comments