Example usage for org.apache.poi.hssf.usermodel HSSFWorkbook createSheet

List of usage examples for org.apache.poi.hssf.usermodel HSSFWorkbook createSheet

Introduction

In this page you can find the example usage for org.apache.poi.hssf.usermodel HSSFWorkbook createSheet.

Prototype


@Override
public HSSFSheet createSheet() 

Source Link

Document

create an HSSFSheet for this HSSFWorkbook, adds it to the sheets and returns the high level representation.

Usage

From source file:de.iteratec.iteraplan.businesslogic.service.legacyExcel.ExcelImportServiceAttributesIntegrationTest.java

License:Open Source License

/**
 * This test case tests the Bug #2192: Fachliche Zuordnungen mit Merkmalen koennen nicht geloescht werden.
 *///w  w w . j a  va2  s.  c o m
@Test
public void testImportBussinesMappingsWithAttributes() {
    InformationSystem is = testDataHelper.createInformationSystem("I");
    TypeOfStatus typeOfStatus = InformationSystemRelease.TypeOfStatus.CURRENT;
    InformationSystemRelease isr = testDataHelper.createInformationSystemRelease(is, "i1", TEST_DESCRIPTION,
            "1.1.2005", "31.12.2005", typeOfStatus);

    BusinessProcess businessProcess = testDataHelper.createBusinessProcess("BP1", "BP1 description");
    BusinessUnit businessUnit = testDataHelper.createBusinessUnit("BU1", "BU1 description");
    Product product = testDataHelper.createProduct("Product1", "Product1 description");
    BusinessMapping businessMapping = testDataHelper.createBusinessMapping(isr, businessProcess, businessUnit,
            product);

    TextAV textAV1 = createTextAttribute("1");
    TextAV textAV2 = createTextAttribute("2");
    TextAV textAV3 = createTextAttribute("3");
    testDataHelper.createAVA(businessMapping, textAV1);
    testDataHelper.createAVA(businessMapping, textAV2);
    testDataHelper.createAVA(businessMapping, textAV3);

    InformationSystem isFromExcel = BuildingBlockFactory.createInformationSystem();
    InformationSystemRelease isrFromExcel = BuildingBlockFactory.createInformationSystemRelease();
    isFromExcel.addRelease(isrFromExcel);
    isFromExcel.setName("NewNameFromExcel");
    isrFromExcel.setId(isr.getId());
    isrFromExcel.setVersion("i1");
    isrFromExcel.setDescription(TEST_DESCRIPTION);
    isrFromExcel.setTypeOfStatus(TypeOfStatus.CURRENT);
    isrFromExcel.setRuntimePeriodNullSafe(new RuntimePeriod(createDate(2005, 1, 1), createDate(2005, 12, 31)));

    final HSSFWorkbook workbook = new HSSFWorkbook();
    final HSSFSheet sheet = workbook.createSheet();
    final HSSFRow row = sheet.createRow(0);
    final Cell nameCell = row.createCell(0);
    final Cell descriptionCell = row.createCell(1);
    final Cell cell = row.createCell(2);
    cell.setCellValue("(BP1 / Product1 / BU1)");

    final Map<String, Cell> isrContentMap = Maps.newHashMap();
    isrContentMap.put("Business Mappings(Business Process / Product / Business Unit)", cell);

    BuildingBlockHolder buildingBlockHolder = new BuildingBlockHolder(isrFromExcel, nameCell, descriptionCell);
    buildingBlockHolder.setClone(BuildingBlockUtil.clone(isrFromExcel));

    LandscapeData landscapeData = new LandscapeData();
    landscapeData.addBuildingBlock(buildingBlockHolder);
    landscapeData.addRelation(isrFromExcel, isrContentMap, Maps.<String, Cell>newHashMap());

    landscapeData.setLocale(Locale.ENGLISH);
    excelImportService.importLandscapeData(landscapeData);

    InformationSystemRelease isrLoadedFromDb = isrService.loadObjectById(isrFromExcel.getId());
    assertEquals("ISR-Name was not changed to excel value!", "NewNameFromExcel",
            isrLoadedFromDb.getNameWithoutVersion());

    BusinessMapping bmLoadedFromDb = businessMappingService.getBusinessMappingByRelatedBuildingBlockIds(
            product.getId(), businessUnit.getId(), businessProcess.getId(), isr.getId());
    Set<AttributeValueAssignment> attributeValueAssignments = bmLoadedFromDb.getAttributeValueAssignments();
    assertEquals("Some attribute value assignments were deleted.", 3, attributeValueAssignments.size());

    checkAttributeValues(attributeValueAssignments, textAV1.getAbstractAttributeType(), "Text Value1");
    checkAttributeValues(attributeValueAssignments, textAV2.getAbstractAttributeType(), "Text Value2");
    checkAttributeValues(attributeValueAssignments, textAV3.getAbstractAttributeType(), "Text Value3");
}

From source file:de.iteratec.iteraplan.businesslogic.service.legacyExcel.ExcelImportServiceAttributesIntegrationTest.java

License:Open Source License

@Test
public void testImportDateAttribute() {
    // create attribute type and sample building block
    AttributeTypeGroup atg = testDataHelper.createAttributeTypeGroup("myTAG", "");
    DateAT dateType = testDataHelper.createDateAttributeType("MyDateType", "", atg);
    testDataHelper.assignAttributeTypeToAllAvailableBuildingBlockTypes(dateType);
    InformationSystem is = testDataHelper.createInformationSystem("myIS");
    InformationSystemRelease isr = testDataHelper.createInformationSystemRelease(is, "1.0");

    // create excel cells with import data
    final HSSFWorkbook workbook = new HSSFWorkbook();
    final CellStyle dateStyle = workbook.createCellStyle();
    dateStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy"));
    final HSSFSheet sheet = workbook.createSheet();
    final HSSFRow row = sheet.createRow(0);
    final Cell cell1 = row.createCell(0);
    cell1.setCellValue(createDate(2010, 12, 31));
    cell1.setCellStyle(dateStyle); // need to do this so our import routines can parse it back as a date value

    Map<String, Cell> attributes = new HashMap<String, Cell>();
    attributes.put(dateType.getName(), cell1);

    LandscapeData landscapeData = new LandscapeData();
    landscapeData.addAttributes(isr, attributes);

    landscapeData.setLocale(Locale.GERMAN);
    excelImportService.importLandscapeData(landscapeData);

    InformationSystemRelease isrLoadedFromDb = isrService.loadObjectById(isr.getId());
    String loadedAv = isrLoadedFromDb.getAttributeValue(dateType.getName(), Locale.GERMAN);
    assertEquals("31.12.2010", loadedAv);

    // following call failed before ITERAPLAN-170 was fixed
    @SuppressWarnings("unused")
    AttributeType at = attributeTypeService.getAttributeTypeByName(dateType.getName());
}

From source file:de.iteratec.iteraplan.businesslogic.service.legacyExcel.ExcelImportServiceImplTest.java

License:Open Source License

@Test
public void testCreateBuildingBlockRelationsBusinessFunction() {
    BusinessFunction bf = createSimpleBusinessFunction();

    // test with an empty relations mapping
    EasyMock.expect(businessFunctionServiceMock.saveOrUpdate(bf)).andReturn(bf);
    EasyMock.replay(businessFunctionServiceMock, businessDomainServiceMock, businessObjectServiceMock,
            bbServiceLocator);//from   w w  w  . ja v  a 2  s  . c  o m
    Map<String, CellValueHolder> bfRelations = new HashMap<String, CellValueHolder>();
    excelImportService.createBuildingBlockRelations(bf, bfRelations, Locale.getDefault());
    Assert.assertTrue("import should not change relation set", bf.getBusinessDomains().isEmpty());
    Assert.assertTrue("import should not change relation set", bf.getBusinessObjects().isEmpty());
    EasyMock.verify(businessFunctionServiceMock, businessDomainServiceMock, businessObjectServiceMock,
            bbServiceLocator);

    final HSSFWorkbook workbook = new HSSFWorkbook();
    final HSSFSheet sheet = workbook.createSheet();
    final HSSFRow row = sheet.createRow(0);
    final Cell cell1 = row.createCell(0);
    final Cell cell2 = row.createCell(1);

    // prepare one Business domain and one business object that exists already in the "DB"
    EasyMock.reset(businessFunctionServiceMock, businessDomainServiceMock, businessObjectServiceMock);
    BusinessDomain bd1 = createSimpleBusinessDomain();
    cell2.setCellValue(bd1.getName());
    CellValueHolder cellValueHolder2 = new CellValueHolder(cell2);
    bfRelations.put(MessageAccess.getStringOrNull("businessDomain.plural"), cellValueHolder2);
    BusinessObject bo1 = createSimpleBusinessObject();
    cell1.setCellValue(bo1.getName());
    CellValueHolder cellValueHolder1 = new CellValueHolder(cell1);
    bfRelations.put(MessageAccess.getStringOrNull("businessObject.plural"), cellValueHolder1);
    // set service expectations
    EasyMock.expect(businessDomainServiceMock.findByNames(Sets.newHashSet(bd1.getName())))
            .andReturn(Arrays.asList(new BusinessDomain[] { bd1 }));
    EasyMock.expect(businessObjectServiceMock.findByNames(Sets.newHashSet(bo1.getName())))
            .andReturn(Arrays.asList(new BusinessObject[] { bo1 }));
    EasyMock.expect(businessFunctionServiceMock.saveOrUpdate(bf)).andReturn(bf);

    // and test
    EasyMock.replay(businessFunctionServiceMock, businessDomainServiceMock, businessObjectServiceMock);
    excelImportService.createBuildingBlockRelations(bf, bfRelations, Locale.getDefault());
    EasyMock.verify(businessFunctionServiceMock, businessDomainServiceMock, businessObjectServiceMock);
    Assert.assertTrue("import should add bd1", bf.getBusinessDomains().contains(bd1));
    Assert.assertTrue("import should add bo1", bf.getBusinessObjects().contains(bo1));

    // next test; reset and clean-up
    EasyMock.reset(businessFunctionServiceMock, businessDomainServiceMock, businessObjectServiceMock);
    bf.setBusinessDomains(new HashSet<BusinessDomain>());
    bf.setBusinessObjects(new HashSet<BusinessObject>());
    // feed in a relation for a non-existent TCR
    EasyMock.expect(businessDomainServiceMock.findByNames(Sets.newHashSet(bd1.getName())))
            .andReturn(new ArrayList<BusinessDomain>());
    EasyMock.expect(businessObjectServiceMock.findByNames(Sets.newHashSet(bo1.getName())))
            .andReturn(new ArrayList<BusinessObject>());
    EasyMock.expect(businessFunctionServiceMock.saveOrUpdate(bf)).andReturn(bf);

    // and test
    EasyMock.replay(businessFunctionServiceMock, businessDomainServiceMock, businessObjectServiceMock);
    excelImportService.createBuildingBlockRelations(bf, bfRelations, Locale.getDefault());
    EasyMock.verify(businessFunctionServiceMock, businessDomainServiceMock, businessObjectServiceMock);
    Assert.assertTrue("import should not add bd1", bf.getBusinessDomains().isEmpty());
    Assert.assertTrue("import should not not bo1", bf.getBusinessObjects().isEmpty());
}

From source file:de.iteratec.iteraplan.businesslogic.service.legacyExcel.ExcelImportServiceImplTest.java

License:Open Source License

@Test
public void testCreateBuildingBlockRelationsArchitecturalDomain() {
    ArchitecturalDomain ad = createSimpleArchitecturalDomain();
    Map<String, CellValueHolder> adRelations = new HashMap<String, CellValueHolder>();

    final HSSFWorkbook workbook = new HSSFWorkbook();
    final HSSFSheet sheet = workbook.createSheet();
    final HSSFRow row = sheet.createRow(0);
    final Cell cell = row.createCell(0);

    // prepare one related TCR that exists already in the DB
    TechnicalComponentRelease tcr1 = new TechnicalComponentRelease();
    TechnicalComponent tc1 = new TechnicalComponent();
    tcr1.setTechnicalComponent(tc1);//from   w  w w  .j av a 2 s .c  o  m
    tcr1.setVersion("1.1");
    tcr1.setId(Integer.valueOf(34131));
    tc1.setName("TC1");
    tc1.setId(Integer.valueOf(646));
    String tcrName = tcr1.getNonHierarchicalName();
    cell.setCellValue(tcrName);

    CellValueHolder cellValueHolder = new CellValueHolder(cell);
    adRelations.put(MessageAccess.getStringOrNull("technicalComponentRelease.plural"), cellValueHolder);
    // set service expectations
    EasyMock.expect(technicalComponentReleaseServiceMock.findByNames(Sets.newHashSet(tcrName)))
            .andReturn(Lists.newArrayList(tcr1));
    EasyMock.expect(architecturalDomainServiceMock.saveOrUpdate(ad)).andReturn(ad);

    // and test
    EasyMock.replay(architecturalDomainServiceMock, technicalComponentReleaseServiceMock, bbServiceLocator);
    excelImportService.createBuildingBlockRelations(ad, adRelations, Locale.getDefault());
    EasyMock.verify(architecturalDomainServiceMock, technicalComponentReleaseServiceMock);
    Assert.assertTrue("import should add tcr1", ad.getTechnicalComponentReleases().contains(tcr1));

    // next test; reset and clean-up
    EasyMock.reset(architecturalDomainServiceMock, technicalComponentReleaseServiceMock);
    ad.setTechnicalComponentReleases(new HashSet<TechnicalComponentRelease>());
    // feed in a relation for a non-existent TCR
    EasyMock.expect(technicalComponentReleaseServiceMock.findByNames(Sets.newHashSet(tcrName)))
            .andReturn(new ArrayList<TechnicalComponentRelease>());
    EasyMock.expect(architecturalDomainServiceMock.saveOrUpdate(ad)).andReturn(ad);

    // and test
    EasyMock.replay(architecturalDomainServiceMock, technicalComponentReleaseServiceMock);
    excelImportService.createBuildingBlockRelations(ad, adRelations, Locale.getDefault());
    EasyMock.verify(architecturalDomainServiceMock, technicalComponentReleaseServiceMock);
    Assert.assertTrue("import should not add tcr1", ad.getTechnicalComponentReleases().isEmpty());
}

From source file:de.iteratec.iteraplan.businesslogic.service.legacyExcel.ExcelImportServiceImplTest.java

License:Open Source License

@SuppressWarnings("boxing")
@Test/*from  ww w  .ja v  a2s.  com*/
public void testSetParentRelation() {
    BusinessDomain childBd = createSimpleBusinessDomain();
    Map<String, CellValueHolder> bdRelations = new HashMap<String, CellValueHolder>();
    childBd.setName("BD2");

    final HSSFWorkbook workbook = new HSSFWorkbook();
    final HSSFSheet sheet = workbook.createSheet();
    final HSSFRow row = sheet.createRow(0);
    final Cell cell0 = row.createCell(0); //hierarchy

    BusinessDomain parentBd1 = new BusinessDomain();
    parentBd1.setName("BD1 : BD2");
    parentBd1.setId(413301);
    String parentName = parentBd1.getNonHierarchicalName();
    cell0.setCellValue(parentName);
    CellValueHolder cellValueHolder0 = new CellValueHolder(cell0);
    bdRelations.put("Fachliche Domnen hierarchisch", cellValueHolder0);

    EasyMock.expect(businessDomainServiceMock.findByNames(Sets.newHashSet("BD1")))
            .andReturn(Lists.newArrayList(parentBd1));
    EasyMock.expect(businessDomainServiceMock.saveOrUpdate(childBd)).andReturn(childBd).anyTimes();

    EasyMock.replay(businessDomainServiceMock, bbServiceLocator);
    excelImportService.createBuildingBlockRelations(childBd, bdRelations, Locale.getDefault());
    EasyMock.verify(businessDomainServiceMock);

    Assert.assertEquals(parentBd1, childBd.getParent());
}

From source file:de.iteratec.iteraplan.businesslogic.service.legacyExcel.ExcelImportServiceImplTest.java

License:Open Source License

@Test
@SuppressWarnings("PMD.ExcessiveMethodLength")
public void testCreateBuildingBlockRelationsBusinessDomain() {
    BusinessDomain bd = createSimpleBusinessDomain();
    Map<String, CellValueHolder> bdRelations = new HashMap<String, CellValueHolder>();

    final HSSFWorkbook workbook = new HSSFWorkbook();
    final HSSFSheet sheet = workbook.createSheet();
    final HSSFRow row = sheet.createRow(0);
    final Cell cell0 = row.createCell(0); //bo
    final Cell cell1 = row.createCell(1); //bf
    final Cell cell2 = row.createCell(2); //bproc
    final Cell cell3 = row.createCell(3); //prod
    final Cell cell4 = row.createCell(4); //bu

    BusinessObject bo1 = new BusinessObject();
    bo1.setName("BO1");
    bo1.setId(Integer.valueOf(34101));
    String boName = bo1.getNonHierarchicalName();
    cell0.setCellValue(boName);//  ww w .  j  a v  a 2s.  com
    CellValueHolder cellValueHolder0 = new CellValueHolder(cell0);
    bdRelations.put(MessageAccess.getStringOrNull("businessObject.plural"), cellValueHolder0);
    // set service expectations
    EasyMock.expect(businessObjectServiceMock.findByNames(Sets.newHashSet(boName)))
            .andReturn(Lists.newArrayList(bo1));

    BusinessFunction bf1 = new BusinessFunction();
    bf1.setName("BF1");
    bf1.setId(Integer.valueOf(4101));
    String bfName = bf1.getNonHierarchicalName();
    cell1.setCellValue(bfName);
    CellValueHolder cellValueHolder1 = new CellValueHolder(cell1);
    bdRelations.put(MessageAccess.getStringOrNull("global.business_functions"), cellValueHolder1);
    // set service expectations
    EasyMock.expect(businessFunctionServiceMock.findByNames(Sets.newHashSet(bfName)))
            .andReturn(Lists.newArrayList(bf1));

    BusinessProcess bproc1 = new BusinessProcess();
    bproc1.setName("BPROC1");
    bproc1.setId(Integer.valueOf(4131));
    String bprocName = bproc1.getNonHierarchicalName();
    cell2.setCellValue(bprocName);
    CellValueHolder cellValueHolder2 = new CellValueHolder(cell2);
    bdRelations.put(MessageAccess.getStringOrNull("businessProcess.plural"), cellValueHolder2);
    // set service expectations
    EasyMock.expect(businessProcessServiceMock.findByNames(Sets.newHashSet(bprocName)))
            .andReturn(Lists.newArrayList(bproc1));

    Product prod1 = new Product();
    prod1.setName("PROD1");
    prod1.setId(Integer.valueOf(422131));
    String prodName = prod1.getNonHierarchicalName();
    cell3.setCellValue(prodName);
    CellValueHolder cellValueHolder3 = new CellValueHolder(cell3);
    bdRelations.put(MessageAccess.getStringOrNull("global.products"), cellValueHolder3);
    // set service expectations
    EasyMock.expect(productServiceMock.findByNames(Sets.newHashSet(prodName)))
            .andReturn(Lists.newArrayList(prod1));

    BusinessUnit bu1 = new BusinessUnit();
    bu1.setName("BU1");
    String buName = bu1.getName();
    cell4.setCellValue(buName);
    CellValueHolder cellValueHolder4 = new CellValueHolder(cell4);
    bdRelations.put(MessageAccess.getStringOrNull("businessUnit.plural"), cellValueHolder4);
    EasyMock.expect(businessUnitServiceMock.findByNames(Sets.newHashSet(buName)))
            .andReturn(Lists.newArrayList(bu1));

    EasyMock.expect(businessDomainServiceMock.saveOrUpdate(bd)).andReturn(bd).anyTimes();
    // and test
    EasyMock.replay(businessDomainServiceMock, businessUnitServiceMock, productServiceMock,
            businessProcessServiceMock, businessFunctionServiceMock, businessObjectServiceMock,
            bbServiceLocator);
    excelImportService.createBuildingBlockRelations(bd, bdRelations, Locale.getDefault());
    EasyMock.verify(businessDomainServiceMock, businessUnitServiceMock, productServiceMock,
            businessObjectServiceMock, businessProcessServiceMock, businessFunctionServiceMock);
    Assert.assertTrue(bd.getBusinessObjects().contains(bo1));
    Assert.assertTrue(bd.getBusinessFunctions().contains(bf1));
    Assert.assertTrue(bd.getBusinessProcesses().contains(bproc1));
    Assert.assertTrue(bd.getProducts().contains(prod1));
    Assert.assertTrue(bd.getBusinessUnits().contains(bu1));

    // next test; reset and clean-up
    EasyMock.reset(businessDomainServiceMock, businessUnitServiceMock, productServiceMock,
            businessObjectServiceMock, businessProcessServiceMock, businessFunctionServiceMock);
    bd.setBusinessObjects(new HashSet<BusinessObject>());
    bd.setBusinessFunctions(new HashSet<BusinessFunction>());
    bd.setBusinessProcesses(new HashSet<BusinessProcess>());
    bd.setBusinessUnits(new HashSet<BusinessUnit>());
    bd.setProducts(new HashSet<Product>());
    // feed in a relation for a non-existent BO
    EasyMock.expect(businessObjectServiceMock.findByNames(Sets.newHashSet(boName)))
            .andReturn(new ArrayList<BusinessObject>());
    EasyMock.expect(businessFunctionServiceMock.findByNames(Sets.newHashSet(bfName)))
            .andReturn(new ArrayList<BusinessFunction>());
    EasyMock.expect(businessProcessServiceMock.findByNames(Sets.newHashSet(bprocName)))
            .andReturn(new ArrayList<BusinessProcess>());
    EasyMock.expect(productServiceMock.findByNames(Sets.newHashSet(prodName)))
            .andReturn(new ArrayList<Product>());
    EasyMock.expect(businessUnitServiceMock.findByNames(Sets.newHashSet(buName)))
            .andReturn(new ArrayList<BusinessUnit>());

    EasyMock.expect(businessDomainServiceMock.saveOrUpdate(bd)).andReturn(bd).anyTimes();
    // and test
    EasyMock.replay(businessDomainServiceMock, businessUnitServiceMock, productServiceMock,
            businessObjectServiceMock, businessFunctionServiceMock, businessProcessServiceMock);
    excelImportService.createBuildingBlockRelations(bd, bdRelations, Locale.getDefault());
    EasyMock.verify(businessDomainServiceMock, businessUnitServiceMock, productServiceMock,
            businessObjectServiceMock, businessFunctionServiceMock, businessProcessServiceMock);
    Assert.assertTrue(bd.getBusinessObjects().isEmpty());
    Assert.assertTrue(bd.getBusinessFunctions().isEmpty());
    Assert.assertTrue(bd.getBusinessProcesses().isEmpty());
    Assert.assertTrue(bd.getProducts().isEmpty());
    Assert.assertTrue(bd.getBusinessUnits().isEmpty());
}

From source file:de.iteratec.iteraplan.businesslogic.service.legacyExcel.ExcelImportServiceImplTest.java

License:Open Source License

@Test
public void testCreateBuildingBlockRelationsBusinessObject() {
    BusinessObject bo = createSimpleBusinessObject();
    Map<String, CellValueHolder> boRelations = new HashMap<String, CellValueHolder>();

    final HSSFWorkbook workbook = new HSSFWorkbook();
    final HSSFSheet sheet = workbook.createSheet();
    final HSSFRow row = sheet.createRow(0);
    final Cell cell0 = row.createCell(0); //bo
    final Cell cell1 = row.createCell(1); //bf
    final Cell cell2 = row.createCell(2); //bd
    final Cell cell3 = row.createCell(3); //isr

    BusinessObject bo1 = new BusinessObject();
    bo1.setName("BO1");
    bo1.setId(Integer.valueOf(34101));
    String boName = bo1.getNonHierarchicalName();
    cell0.setCellValue(boName);//  ww w . j a va  2s .co  m
    CellValueHolder cellValueHolder0 = new CellValueHolder(cell0);
    boRelations.put(MessageAccess.getStringOrNull("global.specialisation"), cellValueHolder0);
    // set service expectations
    EasyMock.expect(businessObjectServiceMock.findByNames(Sets.newHashSet(boName)))
            .andReturn(Lists.newArrayList(bo1));

    BusinessFunction bf1 = new BusinessFunction();
    bf1.setName("BF1");
    bf1.setId(Integer.valueOf(4101));
    String bfName = bf1.getNonHierarchicalName();
    cell1.setCellValue(bfName);
    CellValueHolder cellValueHolder1 = new CellValueHolder(cell1);
    boRelations.put(MessageAccess.getStringOrNull("global.business_functions"), cellValueHolder1);
    // set service expectations
    EasyMock.expect(businessFunctionServiceMock.findByNames(Sets.newHashSet(bfName)))
            .andReturn(Lists.newArrayList(bf1));

    BusinessDomain bd1 = new BusinessDomain();
    bd1.setName("BD1");
    bd1.setId(Integer.valueOf(413301));
    String bdName = bd1.getNonHierarchicalName();
    cell2.setCellValue(bdName);
    CellValueHolder cellValueHolder2 = new CellValueHolder(cell2);
    boRelations.put(MessageAccess.getStringOrNull("businessDomain.plural"), cellValueHolder2);
    // set service expectations
    EasyMock.expect(businessDomainServiceMock.findByNames(Sets.newHashSet(bdName)))
            .andReturn(Lists.newArrayList(bd1));

    InformationSystemRelease isr1 = new InformationSystemRelease();
    InformationSystem is1 = new InformationSystem();
    isr1.setInformationSystem(is1);
    isr1.setVersion("1.2");
    is1.setName("IS1");
    String isrName = isr1.getNonHierarchicalName();
    cell3.setCellValue(isrName);
    CellValueHolder cellValueHolder3 = new CellValueHolder(cell3);
    boRelations.put(MessageAccess.getStringOrNull("informationSystemRelease.plural"), cellValueHolder3);
    // set service expectations
    EasyMock.expect(informationSystemReleaseServiceMock.findByNames(Sets.newHashSet(isrName)))
            .andReturn(Lists.newArrayList(isr1));

    EasyMock.expect(businessObjectServiceMock.saveOrUpdate(bo)).andReturn(bo).anyTimes();
    // and test
    EasyMock.replay(businessObjectServiceMock, businessFunctionServiceMock, businessDomainServiceMock,
            informationSystemReleaseServiceMock, bbServiceLocator);
    excelImportService.createBuildingBlockRelations(bo, boRelations, Locale.getDefault());
    EasyMock.verify(businessObjectServiceMock, businessFunctionServiceMock, businessDomainServiceMock,
            informationSystemReleaseServiceMock);
    Assert.assertTrue(bo.getSpecialisations().contains(bo1));
    Assert.assertTrue(bo.getBusinessFunctions().contains(bf1));
    Assert.assertTrue(bo.getBusinessDomains().contains(bd1));
    Assert.assertTrue(bo.getInformationSystemReleases().contains(isr1));

    // next test; reset and clean-up
    EasyMock.reset(businessObjectServiceMock, businessFunctionServiceMock, businessDomainServiceMock,
            informationSystemReleaseServiceMock);
    bo.setSpecialisations(new HashSet<BusinessObject>());
    bo.setBusinessFunctions(new HashSet<BusinessFunction>());
    bo.setBusinessDomains(new HashSet<BusinessDomain>());
    bo.setInformationSystemReleases(new HashSet<InformationSystemRelease>());
    // feed in a relation for a non-existent BO
    EasyMock.expect(businessObjectServiceMock.findByNames(Sets.newHashSet(boName)))
            .andReturn(new ArrayList<BusinessObject>());
    EasyMock.expect(businessFunctionServiceMock.findByNames(Sets.newHashSet(bfName)))
            .andReturn(new ArrayList<BusinessFunction>());
    EasyMock.expect(businessDomainServiceMock.findByNames(Sets.newHashSet(bdName)))
            .andReturn(new ArrayList<BusinessDomain>());
    EasyMock.expect(informationSystemReleaseServiceMock.findByNames(Sets.newHashSet(isrName)))
            .andReturn(new ArrayList<InformationSystemRelease>());

    EasyMock.expect(businessObjectServiceMock.saveOrUpdate(bo)).andReturn(bo).anyTimes();
    // and test
    EasyMock.replay(businessObjectServiceMock, businessFunctionServiceMock, businessDomainServiceMock,
            informationSystemReleaseServiceMock);
    excelImportService.createBuildingBlockRelations(bo, boRelations, Locale.getDefault());
    EasyMock.verify(businessObjectServiceMock, businessFunctionServiceMock, businessDomainServiceMock,
            informationSystemReleaseServiceMock);
    Assert.assertTrue(bo.getSpecialisations().isEmpty());
    Assert.assertTrue(bo.getBusinessDomains().isEmpty());
    Assert.assertTrue(bo.getBusinessFunctions().isEmpty());
    Assert.assertTrue(bo.getInformationSystemReleases().isEmpty());
}

From source file:de.iteratec.iteraplan.businesslogic.service.legacyExcel.ExcelImportServiceImplTest.java

License:Open Source License

@Test
@SuppressWarnings("PMD.ExcessiveMethodLength")
public void testCreateBuildingBlockRelationsInformationSystemRelease() {
    InformationSystemRelease isr = createSimpleInformationSystemRelease();
    Map<String, CellValueHolder> isrRelations = new HashMap<String, CellValueHolder>();

    final HSSFWorkbook workbook = new HSSFWorkbook();
    final HSSFSheet sheet = workbook.createSheet();
    final HSSFRow row = sheet.createRow(0);
    final Cell cell0 = row.createCell(0); //preced
    final Cell cell1 = row.createCell(1); //success
    final Cell cell3 = row.createCell(3); //bo
    final Cell cell4 = row.createCell(4); //isd
    final Cell cell5 = row.createCell(5); //ie
    final Cell cell6 = row.createCell(6); //proj
    final Cell cell7 = row.createCell(7); //tcr
    final Cell cell8 = row.createCell(8); //is

    InformationSystemRelease isrPred = new InformationSystemRelease();
    InformationSystem isPred = new InformationSystem();
    isrPred.setInformationSystem(isPred);
    isrPred.setVersion("1.2");
    isPred.setName("IS_pred");
    String isrName1 = isrPred.getNonHierarchicalName();
    cell0.setCellValue(isrName1);/*w  w w.  j  a  v a 2  s .c o  m*/
    CellValueHolder cellValueHolder0 = new CellValueHolder(cell0);
    isrRelations.put(MessageAccess.getStringOrNull("global.predecessors"), cellValueHolder0);
    // set service expectations
    EasyMock.expect(informationSystemReleaseServiceMock.findByNames(Sets.newHashSet(isrName1)))
            .andReturn(Lists.newArrayList(isrPred));

    InformationSystemRelease isrSucc = new InformationSystemRelease();
    InformationSystem isSucc = new InformationSystem();
    isrSucc.setInformationSystem(isSucc);
    isrSucc.setVersion("2.3");
    isSucc.setName("IS_succ");
    String isrName2 = isrSucc.getNonHierarchicalName();
    cell1.setCellValue(isrName2);
    CellValueHolder cellValueHolder1 = new CellValueHolder(cell1);
    isrRelations.put(MessageAccess.getStringOrNull("global.successors"), cellValueHolder1);
    // set service expectations
    EasyMock.expect(informationSystemReleaseServiceMock.findByNames(Sets.newHashSet(isrName2)))
            .andReturn(Lists.newArrayList(isrSucc));

    BusinessObject bo1 = new BusinessObject();
    bo1.setName("BO1");
    bo1.setId(Integer.valueOf(34101));
    String boName = bo1.getNonHierarchicalName();
    cell3.setCellValue(boName);
    CellValueHolder cellValueHolder3 = new CellValueHolder(cell3);
    isrRelations.put(MessageAccess.getStringOrNull("businessObject.plural"), cellValueHolder3);
    // set service expectations
    EasyMock.expect(businessObjectServiceMock.findByNames(Sets.newHashSet(boName)))
            .andReturn(Lists.newArrayList(bo1));

    InformationSystemDomain isd1 = new InformationSystemDomain();
    isd1.setName("ISD1");
    isd1.setId(Integer.valueOf(334101));
    String isdName = isd1.getNonHierarchicalName();
    cell4.setCellValue(isdName);
    CellValueHolder cellValueHolder4 = new CellValueHolder(cell4);
    isrRelations.put(MessageAccess.getStringOrNull("informationSystemDomain.plural"), cellValueHolder4);
    // set service expectations
    EasyMock.expect(informationSystemDomainServiceMock.findByNames(Sets.newHashSet(isdName)))
            .andReturn(Lists.newArrayList(isd1));

    InfrastructureElement ie1 = new InfrastructureElement();
    ie1.setName("IE1");
    ie1.setId(Integer.valueOf(34101));
    String ieName = ie1.getNonHierarchicalName();
    cell5.setCellValue(ieName);
    CellValueHolder cellValueHolder5 = new CellValueHolder(cell5);
    isrRelations.put(MessageAccess.getStringOrNull("infrastructureElement.plural"), cellValueHolder5);
    // set service expectations
    EasyMock.expect(infrastructureElementServiceMock.findByNames(Sets.newHashSet(ieName)))
            .andReturn(Lists.newArrayList(ie1));

    Project proj1 = new Project();
    proj1.setName("PROJ1");
    proj1.setId(Integer.valueOf(34101));
    String projName = proj1.getNonHierarchicalName();
    cell6.setCellValue(projName);
    CellValueHolder cellValueHolder6 = new CellValueHolder(cell6);
    isrRelations.put(MessageAccess.getStringOrNull("project.plural"), cellValueHolder6);
    // set service expectations
    EasyMock.expect(projectServiceMock.findByNames(Sets.newHashSet(projName)))
            .andReturn(Lists.newArrayList(proj1));

    TechnicalComponentRelease tcr1 = new TechnicalComponentRelease();
    TechnicalComponent tc1 = new TechnicalComponent();
    tcr1.setTechnicalComponent(tc1);
    tcr1.setVersion("1.1");
    tcr1.setId(Integer.valueOf(34131));
    tc1.setName("TC1");
    tc1.setId(Integer.valueOf(646));
    String tcrName = tcr1.getNonHierarchicalName();
    cell7.setCellValue(tcrName);
    CellValueHolder cellValueHolder7 = new CellValueHolder(cell7);
    isrRelations.put(MessageAccess.getStringOrNull("technicalComponentRelease.plural"), cellValueHolder7);
    // set service expectations
    EasyMock.expect(technicalComponentReleaseServiceMock.findByNames(Sets.newHashSet(tcrName)))
            .andReturn(Lists.newArrayList(tcr1));

    InformationSystemRelease isrBase = new InformationSystemRelease();
    InformationSystem isBase = new InformationSystem();
    isrBase.setInformationSystem(isBase);
    isrBase.setVersion("1.23");
    isBase.setName("IS_base");
    String isrBaseName = isrBase.getNonHierarchicalName();
    cell8.setCellValue(isrBaseName);
    CellValueHolder cellValueHolder8 = new CellValueHolder(cell8);
    isrRelations.put(
            MessageAccess.getStringOrNull("reporting.excel.header.informationSystemRelease.baseComponents"),
            cellValueHolder8);
    // set service expectations
    EasyMock.expect(informationSystemReleaseServiceMock.findByNames(Sets.newHashSet(isrBaseName)))
            .andReturn(Lists.newArrayList(isrBase));

    EasyMock.expect(informationSystemReleaseServiceMock.saveOrUpdate(isr)).andReturn(isr).anyTimes();
    // and test
    EasyMock.replay(informationSystemReleaseServiceMock, businessObjectServiceMock,
            informationSystemDomainServiceMock, infrastructureElementServiceMock, projectServiceMock,
            technicalComponentReleaseServiceMock, informationSystemServiceMock, bbServiceLocator);
    excelImportService.createBuildingBlockRelations(isr, isrRelations, Locale.getDefault());
    EasyMock.verify(informationSystemReleaseServiceMock, businessObjectServiceMock,
            informationSystemDomainServiceMock, infrastructureElementServiceMock, projectServiceMock,
            technicalComponentReleaseServiceMock, informationSystemServiceMock);
    Assert.assertTrue(isr.getPredecessors().contains(isrPred));
    Assert.assertTrue(isr.getSuccessors().contains(isrSucc));
    Assert.assertTrue(isr.getBusinessObjects().contains(bo1));
    Assert.assertTrue(isr.getInformationSystemDomains().contains(isd1));
    Assert.assertTrue(isr.getInfrastructureElements().contains(ie1));
    Assert.assertTrue(isr.getProjects().contains(proj1));
    Assert.assertTrue(isr.getTechnicalComponentReleases().contains(tcr1));
    Assert.assertTrue(isr.getBaseComponents().contains(isrBase));

    // next test; reset and clean-up
    EasyMock.reset(informationSystemReleaseServiceMock, businessObjectServiceMock,
            informationSystemDomainServiceMock, infrastructureElementServiceMock, projectServiceMock,
            technicalComponentReleaseServiceMock, informationSystemServiceMock);
    isr.setPredecessors(new HashSet<InformationSystemRelease>());
    isr.setSuccessors(new HashSet<InformationSystemRelease>());
    isr.setBusinessObjects(new HashSet<BusinessObject>());
    isr.setInformationSystemDomains(new HashSet<InformationSystemDomain>());
    isr.setInfrastructureElements(new HashSet<InfrastructureElement>());
    isr.setProjects(new HashSet<Project>());
    isr.setTechnicalComponentReleases(new HashSet<TechnicalComponentRelease>());
    isr.setBaseComponents(new HashSet<InformationSystemRelease>());
    // feed in a relation for a non-existent BO
    EasyMock.expect(informationSystemReleaseServiceMock.findByNames(Sets.newHashSet(isrName1)))
            .andReturn(new ArrayList<InformationSystemRelease>());
    EasyMock.expect(informationSystemReleaseServiceMock.findByNames(Sets.newHashSet(isrName2)))
            .andReturn(new ArrayList<InformationSystemRelease>());
    EasyMock.expect(businessObjectServiceMock.findByNames(Sets.newHashSet(boName)))
            .andReturn(new ArrayList<BusinessObject>());
    EasyMock.expect(informationSystemDomainServiceMock.findByNames(Sets.newHashSet(isdName)))
            .andReturn(new ArrayList<InformationSystemDomain>());
    EasyMock.expect(infrastructureElementServiceMock.findByNames(Sets.newHashSet(ieName)))
            .andReturn(new ArrayList<InfrastructureElement>());
    EasyMock.expect(projectServiceMock.findByNames(Sets.newHashSet(projName)))
            .andReturn(new ArrayList<Project>());
    EasyMock.expect(technicalComponentReleaseServiceMock.findByNames(Sets.newHashSet(tcrName)))
            .andReturn(new ArrayList<TechnicalComponentRelease>());
    EasyMock.expect(informationSystemReleaseServiceMock.findByNames(Sets.newHashSet(isrBaseName)))
            .andReturn(new ArrayList<InformationSystemRelease>());

    EasyMock.expect(informationSystemReleaseServiceMock.saveOrUpdate(isr)).andReturn(isr).anyTimes();
    // and test
    EasyMock.replay(informationSystemReleaseServiceMock, businessObjectServiceMock,
            informationSystemDomainServiceMock, infrastructureElementServiceMock, projectServiceMock,
            technicalComponentReleaseServiceMock, informationSystemServiceMock);
    excelImportService.createBuildingBlockRelations(isr, isrRelations, Locale.getDefault());
    EasyMock.verify(informationSystemReleaseServiceMock, businessObjectServiceMock,
            informationSystemDomainServiceMock, infrastructureElementServiceMock, projectServiceMock,
            technicalComponentReleaseServiceMock, informationSystemServiceMock);
    Assert.assertTrue(isr.getPredecessors().isEmpty());
    Assert.assertTrue(isr.getSuccessors().isEmpty());
    Assert.assertTrue(isr.getBusinessObjects().isEmpty());
    Assert.assertTrue(isr.getInformationSystemDomains().isEmpty());
    Assert.assertTrue(isr.getInfrastructureElements().isEmpty());
    Assert.assertTrue(isr.getProjects().isEmpty());
    Assert.assertTrue(isr.getTechnicalComponentReleases().isEmpty());
    Assert.assertTrue(isr.getBaseComponents().isEmpty());

}

From source file:de.iteratec.iteraplan.businesslogic.service.legacyExcel.ImportServiceIntegrationTest.java

License:Open Source License

/**
 * Tests what the Importer does, when the ISR blocks have cycles. It is still not clear, how we will
 * fix it.//from  w  w w .  ja  va2s  . co  m
 */
@Test
public void testCycles() {
    InformationSystemRelease isr1 = createSampleISR(TEST_ISR_NAME, "");
    InformationSystemRelease isr2 = createSampleISR("ISR2", "");
    InformationSystemRelease isr3 = createSampleISR("ISR3", "");

    final HSSFWorkbook workbook = new HSSFWorkbook();
    final HSSFSheet sheet = workbook.createSheet();
    final HSSFRow row = sheet.createRow(0);
    final Cell cell1 = row.createCell(0);
    final Cell cell2 = row.createCell(1);
    final Cell cell3 = row.createCell(2);

    cell1.setCellValue("ISR3 : ISR1");
    cell2.setCellValue("ISR1 : ISR2");
    cell3.setCellValue("ISR2 : ISR3");

    final Map<String, Cell> isr1Content = ImmutableMap.of("Information Systems hierarchical", cell1);
    final Map<String, Cell> isr2Content = ImmutableMap.of("Information Systems hierarchical", cell2);
    final Map<String, Cell> isr3Content = ImmutableMap.of("Information Systems hierarchical", cell3);
    final Map<String, Cell> emptyMap = Collections.emptyMap();

    LandscapeData landscapeData = new LandscapeData();
    BuildingBlockHolder isr1Holder = new BuildingBlockHolder(isr1, null, null);
    BuildingBlockHolder isr2Holder = new BuildingBlockHolder(isr2, null, null);
    BuildingBlockHolder isr3Holder = new BuildingBlockHolder(isr3, null, null);

    isr1Holder.setClone(BuildingBlockUtil.clone(isr1));
    isr2Holder.setClone(BuildingBlockUtil.clone(isr2));
    isr3Holder.setClone(BuildingBlockUtil.clone(isr3));

    landscapeData.addBuildingBlock(isr1Holder);
    landscapeData.addBuildingBlock(isr2Holder);
    landscapeData.addBuildingBlock(isr3Holder);
    landscapeData.addRelation(isr1, isr1Content, emptyMap);
    landscapeData.addRelation(isr2, isr2Content, emptyMap);
    landscapeData.addRelation(isr3, isr3Content, emptyMap);

    landscapeData.setLocale(Locale.ENGLISH);
    excelImportService.importLandscapeData(landscapeData);

    isr1 = isrService.loadObjectByIdIfExists(isr1.getId());
    assertEquals(isr3, isr1.getParent());
    isr2 = isrService.loadObjectByIdIfExists(isr2.getId());
    assertEquals(isr1, isr2.getParent());
    isr3 = isrService.loadObjectByIdIfExists(isr3.getId());
    assertNull(isr3.getParent());
}

From source file:de.iteratec.iteraplan.businesslogic.service.legacyExcel.ImportServiceIntegrationTest.java

License:Open Source License

/**
 * Tests the direction of the Business Objects for the imported ISI building block.
 * //from  w  w w.  ja va  2  s .co m
 * @throws Exception if an import exception occurs
 */
@Test
public void testISIBusinessObjectsDirection() throws Exception {
    BusinessObject customerBO = testDataHelper.createBusinessObject("Customer", "");
    testDataHelper.createBusinessObject("Rating", "");
    testDataHelper.createBusinessObject("Accounting entry", "");

    InformationSystem isA = testDataHelper.createInformationSystem(TEST_ISR_NAME);
    InformationSystemRelease isrA = testDataHelper.createInformationSystemRelease(isA, "1", TEST_DESCRIPTION,
            "1.1.2005", "31.12.2005", InformationSystemRelease.TypeOfStatus.CURRENT);

    InformationSystem isB = testDataHelper.createInformationSystem("ISR2");
    InformationSystemRelease isrB = testDataHelper.createInformationSystemRelease(isB, "1", TEST_DESCRIPTION,
            "1.1.2006", "31.12.2006", InformationSystemRelease.TypeOfStatus.CURRENT);

    InformationSystemInterface informationSystemInterface = testDataHelper
            .createInformationSystemInterfaceWithNameDirection("", "-", "Interface description", isrA, isrB,
                    null);
    assertNotNull(informationSystemInterface);
    Transport transport = testDataHelper.createTransport(customerBO, informationSystemInterface,
            Direction.BOTH_DIRECTIONS);
    transportService.saveOrUpdate(transport);

    final Map<String, Cell> content = Maps.newHashMap();

    final HSSFWorkbook workbook = new HSSFWorkbook();
    final HSSFSheet sheet = workbook.createSheet();
    final HSSFRow row = sheet.createRow(0);
    final Cell cell1 = row.createCell(0);
    final Cell cell2 = row.createCell(1);
    final Cell cell3 = row.createCell(2);
    final Cell cell4 = row.createCell(3);

    cell1.setCellValue("ISR1 # 1");
    cell2.setCellValue("ISR2 # 1");
    cell3.setCellValue("Interface description");
    cell4.setCellValue("-> Customer; <- Rating; <-> Accounting entry ");

    content.put("Information System A", cell1);
    content.put("Information System B", cell2);
    content.put("Description", cell3);
    content.put("Transported Business Objects", cell4);

    final Map<String, Cell> emptyMap = Collections.emptyMap();

    LandscapeData landscapeData = new LandscapeData();
    landscapeData.addRelation(informationSystemInterface, content, emptyMap);

    landscapeData.setLocale(Locale.ENGLISH);
    excelImportService.importLandscapeData(landscapeData);

    InformationSystemInterface isiLoaded = isiService
            .loadObjectByIdIfExists(informationSystemInterface.getId());
    assertNotNull(isiLoaded);

    final Set<Transport> transports = isiLoaded.getTransports();
    assertFalse(transports.isEmpty());
    assertEquals(3, transports.size());

    checkTransportDirection(transports, "Customer", "->");
    checkTransportDirection(transports, "Rating", "<-");
    checkTransportDirection(transports, "Accounting entry", "<->");
}