Skip to content

Data importer #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.0.3

* Added the EclipseStoreDataImporter to import data from JPA repositories.

# 1.0.2

* Added the EclipseStoreCustomRepository which has no methods defined at all.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package software.xdev.spring.data.eclipse.store.jpa;
package software.xdev.spring.data.eclipse.store.jpa.integration;

import static org.springframework.test.annotation.DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD;

Expand All @@ -28,16 +28,13 @@
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import software.xdev.spring.data.eclipse.store.repository.config.EnableEclipseStoreRepositories;


@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = {TestConfiguration.class})
@DirtiesContext(classMode = BEFORE_EACH_TEST_METHOD)
@TestPropertySource("/application.properties")
@EnableEclipseStoreRepositories
public @interface DefaultTestAnnotations
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,70 @@
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

import software.xdev.spring.data.eclipse.store.jpa.DefaultTestAnnotations;
import software.xdev.spring.data.eclipse.store.jpa.integration.repository.PersonToTest;
import software.xdev.spring.data.eclipse.store.jpa.integration.repository.PersonToTestRepository;
import software.xdev.spring.data.eclipse.store.importer.EclipseStoreDataImporterComponent;
import software.xdev.spring.data.eclipse.store.jpa.integration.repository.PersonToTestInEclipseStore;
import software.xdev.spring.data.eclipse.store.jpa.integration.repository.PersonToTestInEclipseStoreRepository;
import software.xdev.spring.data.eclipse.store.jpa.integration.repository.PersonToTestInJpa;
import software.xdev.spring.data.eclipse.store.jpa.integration.repository.PersonToTestInJpaRepository;
import software.xdev.spring.data.eclipse.store.repository.EclipseStoreStorage;
import software.xdev.spring.data.eclipse.store.repository.support.SimpleEclipseStoreRepository;


@DefaultTestAnnotations
public class IntegrationTest
class IntegrationTest
{
@Autowired
private PersonToTestRepository personToTestRepository;
private PersonToTestInEclipseStoreRepository personToTestInEclipseStoreRepository;

@Autowired
private PersonToTestInJpaRepository personToTestInJpaRepository;

@Autowired
private EclipseStoreDataImporterComponent eclipseStoreDataImporter;

@Autowired
private EclipseStoreStorage eclipseStoreStorage;

/**
* Super simple test if there are any start-up errors when running parallel to a JPA configuration
*/
@Test
void testBasicSaveAndFindSingleRecords()
{
final PersonToTest customer = new PersonToTest("", "");
this.personToTestRepository.save(customer);
final PersonToTestInEclipseStore customer = new PersonToTestInEclipseStore("", "");
this.personToTestInEclipseStoreRepository.save(customer);

final List<PersonToTest> customers = this.personToTestRepository.findAll();
final List<PersonToTestInEclipseStore> customers = this.personToTestInEclipseStoreRepository.findAll();
Assertions.assertEquals(1, customers.size());
Assertions.assertEquals(customer, customers.get(0));
}

@Test
void testEclipseStoreImport()
{
final PersonToTestInJpa customer = new PersonToTestInJpa("1", "", "");
this.personToTestInJpaRepository.save(customer);

final List<SimpleEclipseStoreRepository<?, ?>> simpleEclipseStoreRepositories =
this.eclipseStoreDataImporter.importData();
Assertions.assertEquals(1, simpleEclipseStoreRepositories.size());
final List<?> allEntities = simpleEclipseStoreRepositories.get(0).findAll();
Assertions.assertEquals(1, allEntities.size());

this.eclipseStoreStorage.stop();
Assertions.assertEquals(
1,
this.eclipseStoreStorage.getEntityCount(PersonToTestInJpa.class),
"After restart the imported entities are not there anymore.");
}

@Test
void testEclipseStoreEmptyImport()
{
final List<SimpleEclipseStoreRepository<?, ?>> simpleEclipseStoreRepositories =
this.eclipseStoreDataImporter.importData();
Assertions.assertEquals(1, simpleEclipseStoreRepositories.size());
final List<?> allEntities = simpleEclipseStoreRepositories.get(0).findAll();
Assertions.assertEquals(0, allEntities.size());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package software.xdev.spring.data.eclipse.store.jpa;
package software.xdev.spring.data.eclipse.store.jpa.integration;

import java.nio.file.Path;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.EventListener;
Expand All @@ -28,8 +31,12 @@
import software.xdev.spring.data.eclipse.store.repository.EclipseStoreStorage;
import software.xdev.spring.data.eclipse.store.repository.config.EnableEclipseStoreRepositories;


@Configuration
@ComponentScan("software.xdev.spring.data.eclipse.store.importer")
@EnableEclipseStoreRepositories
@SpringBootConfiguration
@EnableAutoConfiguration
public class TestConfiguration implements DisposableBean
{
@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
import org.springframework.data.annotation.Id;


public class PersonToTest
public class PersonToTestInEclipseStore
{
@Id
private String id;

private final String firstName;
private final String lastName;

public PersonToTest(final String firstName, final String lastName)
public PersonToTestInEclipseStore(final String firstName, final String lastName)
{
this.firstName = firstName;
this.lastName = lastName;
Expand All @@ -30,7 +30,7 @@ public boolean equals(final Object o)
{
return false;
}
final PersonToTest customer = (PersonToTest)o;
final PersonToTestInEclipseStore customer = (PersonToTestInEclipseStore)o;
return Objects.equals(this.id, customer.id) && Objects.equals(this.firstName, customer.firstName)
&& Objects.equals(this.lastName, customer.lastName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
import software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStoreListCrudRepository;


public interface PersonToTestRepository extends EclipseStoreListCrudRepository<PersonToTest, String>
public interface PersonToTestInEclipseStoreRepository extends EclipseStoreListCrudRepository<PersonToTestInEclipseStore, String>
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package software.xdev.spring.data.eclipse.store.jpa.integration.repository;

import java.util.Objects;

import jakarta.persistence.Entity;
import jakarta.persistence.Id;


@Entity
public class PersonToTestInJpa
{
@Id
private String id;

private String firstName;
private String lastName;

public PersonToTestInJpa(final String id, final String firstName, final String lastName)
{
this.id = id;
this.firstName = firstName;
this.lastName = lastName;
}

public PersonToTestInJpa()
{

}

@Override
public boolean equals(final Object o)
{
if(this == o)
{
return true;
}
if(o == null || this.getClass() != o.getClass())
{
return false;
}
final PersonToTestInJpa customer = (PersonToTestInJpa)o;
return Objects.equals(this.id, customer.id) && Objects.equals(this.firstName, customer.firstName)
&& Objects.equals(this.lastName, customer.lastName);
}

@Override
public int hashCode()
{
return Objects.hash(this.id, this.firstName, this.lastName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package software.xdev.spring.data.eclipse.store.jpa.integration.repository;

import org.springframework.data.jpa.repository.JpaRepository;


public interface PersonToTestInJpaRepository extends JpaRepository<PersonToTestInJpa, String>
{
}
Loading