-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d6477cb
commit d739978
Showing
6 changed files
with
80 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/com/gepardec/mega/zep/mapper/MapperUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.gepardec.mega.zep.mapper; | ||
|
||
import java.time.LocalDate; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.stream.Collectors; | ||
|
||
import com.gepardec.mega.domain.utils.DateUtils; | ||
import de.provantis.zep.AttributesType; | ||
import de.provantis.zep.AttributeType; | ||
|
||
|
||
public class MapperUtil { | ||
public static Map<String, String> convertAttributesToMap(AttributesType attributes) { | ||
if (attributes == null) | ||
return null; | ||
return attributes.getAttribute().stream() | ||
.filter(Objects::nonNull) | ||
.collect(Collectors.toMap(de.provantis.zep.AttributeType::getName, AttributeType::getValue)); | ||
} | ||
|
||
public static LocalDate convertStringToDate(String dateString) { | ||
if (dateString == null) | ||
return null; | ||
|
||
return DateUtils.parseDate(dateString); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/test/java/com/gepardec/mega/zep/mapper/MapperUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.gepardec.mega.zep.mapper; | ||
|
||
import de.provantis.zep.AttributeType; | ||
import de.provantis.zep.AttributesType; | ||
import com.gepardec.mega.domain.model.ProjectTime; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.time.LocalDate; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class MapperUtilTest { | ||
@Test | ||
void DateString_convertsToLocalDate() { | ||
String dateString = "2002-11-23"; | ||
LocalDate date = MapperUtil.convertStringToDate(dateString); | ||
assertThat(date.toString()).isEqualTo(dateString); | ||
} | ||
|
||
@Test | ||
void whenAttributes_thenReturnsAttributesMap() { | ||
AttributeType attribute = new de.provantis.zep.AttributeType(); | ||
attribute.setName("gilde"); | ||
attribute.setValue("cia"); | ||
AttributeType attribute2 = new de.provantis.zep.AttributeType(); | ||
attribute2.setName("office"); | ||
attribute2.setValue("wien"); | ||
|
||
List<AttributeType> attributesList = new ArrayList<>(); | ||
attributesList.add(attribute); | ||
attributesList.add(attribute2); | ||
|
||
AttributesType attributes = new de.provantis.zep.AttributesType(); | ||
attributes.setAttribute(attributesList); | ||
|
||
Map<String, String> attributesMap = MapperUtil.convertAttributesToMap(attributes); | ||
|
||
assertThat(attributesMap.get(attribute.getName())).isEqualTo(attribute.getValue()); | ||
assertThat(attributesMap.get(attribute2.getName())).isEqualTo(attribute2.getValue()); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters