-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Otavio Santana <otaviopolianasantana@gmail.com>
- Loading branch information
1 parent
46ff246
commit e7bcdc4
Showing
3 changed files
with
252 additions
and
0 deletions.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
...e/mapping-lite-core-test/src/main/java/org/eclipse/jnosql/lite/mapping/entities/Wine.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,84 @@ | ||
/* | ||
* Copyright (c) 2024 Contributors to the Eclipse Foundation | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* and Apache License v2.0 which accompanies this distribution. | ||
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html | ||
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. | ||
* | ||
* You may elect to redistribute this code under either of these licenses. | ||
* | ||
* Contributors: | ||
* | ||
* Otavio Santana | ||
*/ | ||
package org.eclipse.jnosql.lite.mapping.entities; | ||
|
||
|
||
import jakarta.nosql.Column; | ||
import jakarta.nosql.Entity; | ||
import jakarta.nosql.Id; | ||
|
||
import java.util.Objects; | ||
|
||
@Entity | ||
public class Wine { | ||
|
||
@Id | ||
private String id; | ||
|
||
@Column | ||
private String name; | ||
|
||
@Column | ||
private WineFactory factory; | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public WineFactory getFactory() { | ||
return factory; | ||
} | ||
|
||
void setId(String id) { | ||
this.id = id; | ||
} | ||
|
||
void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
void setFactory(WineFactory factory) { | ||
this.factory = factory; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
Wine wine = (Wine) o; | ||
return Objects.equals(id, wine.id); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hashCode(id); | ||
} | ||
|
||
public static Wine of(String id, String name, WineFactory factory) { | ||
Wine wine = new Wine(); | ||
wine.name = name; | ||
wine.id = id; | ||
wine.factory = factory; | ||
return wine; | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...ng-lite-core-test/src/main/java/org/eclipse/jnosql/lite/mapping/entities/WineFactory.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,62 @@ | ||
/* | ||
* Copyright (c) 2024 Contributors to the Eclipse Foundation | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* and Apache License v2.0 which accompanies this distribution. | ||
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html | ||
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. | ||
* | ||
* You may elect to redistribute this code under either of these licenses. | ||
* | ||
* Contributors: | ||
* | ||
* Otavio Santana | ||
*/ | ||
package org.eclipse.jnosql.lite.mapping.entities; | ||
|
||
import jakarta.nosql.Column; | ||
import jakarta.nosql.Embeddable; | ||
|
||
import static jakarta.nosql.Embeddable.EmbeddableType.GROUPING; | ||
|
||
@Embeddable(GROUPING) | ||
public class WineFactory { | ||
|
||
@Column | ||
private String name; | ||
|
||
@Column | ||
private String location; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getLocation() { | ||
return location; | ||
} | ||
|
||
void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
void setLocation(String location) { | ||
this.location = location; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "WineFactory{" + | ||
"name='" + name + '\'' + | ||
", location='" + location + '\'' + | ||
'}'; | ||
} | ||
|
||
public static WineFactory of(String name, String location) { | ||
WineFactory factory = new WineFactory(); | ||
factory.name = name; | ||
factory.location = location; | ||
return factory; | ||
} | ||
|
||
} |
106 changes: 106 additions & 0 deletions
106
...pping-lite-core-test/src/test/java/org/eclipse/jnosql/lite/mapping/entities/WineTest.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,106 @@ | ||
/* | ||
* Copyright (c) 2024 Otávio Santana and others | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* and Apache License v2.0 which accompanies this distribution. | ||
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html | ||
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. | ||
* | ||
* You may elect to redistribute this code under either of these licenses. | ||
* | ||
* Contributors: | ||
* | ||
* Otavio Santana | ||
*/ | ||
package org.eclipse.jnosql.lite.mapping.entities; | ||
|
||
import org.assertj.core.api.SoftAssertions; | ||
import org.eclipse.jnosql.lite.mapping.metadata.LiteEntitiesMetadata; | ||
import org.eclipse.jnosql.mapping.metadata.EntitiesMetadata; | ||
import org.eclipse.jnosql.mapping.metadata.EntityMetadata; | ||
import org.eclipse.jnosql.mapping.metadata.FieldMetadata; | ||
import org.eclipse.jnosql.mapping.metadata.GenericFieldMetadata; | ||
import org.eclipse.jnosql.mapping.metadata.MappingType; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
class WineTest { | ||
|
||
private EntitiesMetadata mappings; | ||
|
||
private EntityMetadata entityMetadata; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
this.mappings = new LiteEntitiesMetadata(); | ||
this.entityMetadata = this.mappings.get(Wine.class); | ||
} | ||
|
||
@Test | ||
void shouldGetName() { | ||
Assertions.assertEquals("Wine", entityMetadata.name()); | ||
} | ||
|
||
@Test | ||
void shouldGetSimpleName() { | ||
Assertions.assertEquals(Wine.class.getSimpleName(), entityMetadata.simpleName()); | ||
} | ||
|
||
@Test | ||
void shouldGetClassName() { | ||
Assertions.assertEquals(Wine.class.getName(), entityMetadata.className()); | ||
} | ||
|
||
@Test | ||
void shouldGetClassInstance() { | ||
Assertions.assertEquals(Wine.class, entityMetadata.type()); | ||
} | ||
|
||
@Test | ||
void shouldGetId() { | ||
Optional<FieldMetadata> id = this.entityMetadata.id(); | ||
Assertions.assertTrue(id.isPresent()); | ||
} | ||
|
||
@Test | ||
void shouldCreateNewInstance() { | ||
Wine wine = entityMetadata.newInstance(); | ||
Assertions.assertNotNull(wine); | ||
Assertions.assertTrue(wine instanceof Wine); | ||
} | ||
|
||
@Test | ||
void shouldGetFieldsName() { | ||
List<String> fields = entityMetadata.fieldsName(); | ||
Assertions.assertEquals(3, fields.size()); | ||
Assertions.assertTrue(fields.contains("id")); | ||
Assertions.assertTrue(fields.contains("name")); | ||
Assertions.assertTrue(fields.contains("factory")); | ||
} | ||
|
||
@Test | ||
void shouldGetFieldsGroupByName() { | ||
Map<String, FieldMetadata> groupByName = this.entityMetadata.fieldsGroupByName(); | ||
Assertions.assertNotNull(groupByName); | ||
Assertions.assertNotNull(groupByName.get("_id")); | ||
Assertions.assertNotNull(groupByName.get("name")); | ||
Assertions.assertNotNull(groupByName.get("factory")); | ||
} | ||
|
||
|
||
@Test | ||
public void shouldReturnGrouping() { | ||
Map<String, FieldMetadata> groupByName = this.entityMetadata.fieldsGroupByName(); | ||
FieldMetadata factory = groupByName.get("factory"); | ||
SoftAssertions.assertSoftly(soft -> { | ||
soft.assertThat(factory.type()).isEqualTo(WineFactory.class); | ||
soft.assertThat(factory.mappingType()).isEqualTo(MappingType.EMBEDDED_GROUP); | ||
}); | ||
} | ||
} |