Skip to content

Commit

Permalink
Merge d9b037f into 05d8d1c
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinYSpasov committed May 30, 2019
2 parents 05d8d1c + d9b037f commit e2117f2
Show file tree
Hide file tree
Showing 42 changed files with 956 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on [Keep a CHANGELOG](http://keepachangelog.com/). This project adheres to

## [Unreleased]
### Added
- Unifiedsearch indexer module
- Integration test for event catchup
- Integration test for PublishedEvent rebuild.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package uk.gov.justice.services.example.cakeshop.persistence;

import uk.gov.justice.services.example.cakeshop.persistence.entity.Index;

import java.util.UUID;

import org.apache.deltaspike.data.api.EntityRepository;
import org.apache.deltaspike.data.api.Repository;

@Repository
public interface IndexRepository extends EntityRepository<Index, UUID> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package uk.gov.justice.services.example.cakeshop.persistence.entity;

import java.io.Serializable;
import java.time.ZonedDateTime;
import java.util.Objects;
import java.util.UUID;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "index")
public class Index implements Serializable {

@Id
@Column(name = "index_id")
private UUID indexId;

@Column(name = "delivery_date", nullable = false, insertable = true, updatable = true)
private ZonedDateTime deliveryDate;

public Index(final UUID indexId, final ZonedDateTime deliveryDate) {
this.indexId = indexId;
this.deliveryDate = deliveryDate;
}

public Index() {

}

public UUID getIndexId() {
return indexId;
}

public ZonedDateTime getDeliveryDate() {
return deliveryDate;
}


@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final Index index = (Index) o;
return indexId.equals(index.indexId) &&
deliveryDate.equals(index.deliveryDate);
}

@Override
public int hashCode() {
return Objects.hash(indexId, deliveryDate);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public class CakeOrderRepositoryIT extends BaseTransactionalTest {
@Inject
private CakeOrderRepository cakeOrderRepository;

private CakeOrder cakeOrderA;

@Test
public void shouldStoreOrder() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package uk.gov.justice.services.example.cakeshop.persistence;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;

import uk.gov.justice.services.example.cakeshop.persistence.entity.Index;
import uk.gov.justice.services.test.utils.persistence.BaseTransactionalTest;

import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.UUID;

import javax.inject.Inject;

import org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(CdiTestRunner.class)
public class IndexRepositoryIT extends BaseTransactionalTest {

@Inject
private IndexRepository indexRepository;


@Test
public void shouldStoreIndex() {
final UUID indexId = UUID.randomUUID();
final ZonedDateTime deliveryDate = ZonedDateTime.of(2014, 5, 13, 4, 12, 12, 0, ZoneId.of("UTC"));

final Index index = new Index(indexId, deliveryDate);
indexRepository.save(index);

final Index indexResult = indexRepository.findBy(indexId);

assertThat(indexResult, is(notNullValue()));
assertThat(indexResult.getIndexId(), equalTo(indexId));
assertThat(indexResult.getDeliveryDate(), equalTo(deliveryDate));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package uk.gov.justice.services.example.cakeshop.persistence.entity;

import static java.time.ZonedDateTime.now;
import static java.util.UUID.*;

import java.time.ZonedDateTime;
import java.util.UUID;

import com.google.common.testing.EqualsTester;
import org.junit.Test;

public class IndexTest {

private final static UUID ID = randomUUID();
private final static ZonedDateTime TIME = now();

@SuppressWarnings({"squid:MethodCyclomaticComplexity", "squid:S1067", "squid:S00122"})
@Test
public void equalsAndHashCode() {
final Index item1 = new Index(ID, TIME);
final Index item2 = new Index(ID, TIME);
final Index item3 = new Index(randomUUID(), TIME);

new EqualsTester()
.addEqualityGroup(item1, item2)
.addEqualityGroup(item3)
.testEquals();
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>example-event</artifactId>
<groupId>uk.gov.justice.services.example</groupId>
<version>2.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>example-event-indexer</artifactId>
<packaging>war</packaging>

<properties>
<cpp.service-component>EVENT_INDEXER</cpp.service-component>
</properties>

<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>uk.gov.justice.framework-api</groupId>
<artifactId>framework-api-core</artifactId>
</dependency>

<dependency>
<groupId>uk.gov.justice.framework-api</groupId>
<artifactId>framework-api-unifiedsearch</artifactId>
</dependency>

<dependency>
<groupId>uk.gov.justice.services</groupId>
<artifactId>common</artifactId>
<version>${framework.version}</version>
</dependency>
<dependency>
<groupId>uk.gov.justice.services</groupId>
<artifactId>core</artifactId>
<version>${framework.version}</version>
</dependency>
<dependency>
<groupId>uk.gov.justice.framework-generators</groupId>
<artifactId>messaging-adapter-core</artifactId>
<version>${framework-generators.version}</version>
</dependency>
<dependency>
<groupId>uk.gov.justice.framework-generators</groupId>
<artifactId>unifiedsearch-client-generator</artifactId>
<version>${framework-generators.version}</version>
<exclusions>
<exclusion>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>uk.gov.justice.event-store</groupId>
<artifactId>subscription-manager</artifactId>
<version>${event-store.version}</version>
</dependency>
<dependency>
<groupId>uk.gov.justice.event-store</groupId>
<artifactId>event-subscription-registry</artifactId>
<version>${event-store.version}</version>
</dependency>
<dependency>
<groupId>uk.gov.justice.event-store</groupId>
<artifactId>subscription-event-interceptors</artifactId>
<version>${event-store.version}</version>
</dependency>
<dependency>
<groupId>uk.gov.justice.framework-api</groupId>
<artifactId>framework-api-event-listener-interceptors</artifactId>
<version>${framework-api.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.ejb3</groupId>
<artifactId>jboss-ejb3-ext-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>uk.gov.justice.services.example</groupId>
<artifactId>example-persistence</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>uk.gov.justice.services.example</groupId>
<artifactId>example-domain</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>uk.gov.justice.event-store</groupId>
<artifactId>event-buffer-core</artifactId>
<version>${event-store.version}</version>
</dependency>

<dependency>
<groupId>uk.gov.justice.json</groupId>
<artifactId>json-transformer-jolt</artifactId>
<version>${json-transformer.version}</version>
</dependency>

<!-- Test Dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>uk.gov.justice.services</groupId>
<artifactId>test-utils-core</artifactId>
<version>${framework.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>uk.gov.justice.utils</groupId>
<artifactId>test-utils-logging-simple</artifactId>
<type>pom</type>
<scope>test</scope>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package uk.gov.justice.services.example.cakeshop.dummy;

import static java.util.UUID.fromString;

import uk.gov.justice.services.example.cakeshop.persistence.IndexRepository;
import uk.gov.justice.services.example.cakeshop.persistence.entity.Index;
import uk.gov.justice.services.unifiedsearch.UnifiedSearchIndexer;

import java.time.ZonedDateTime;
import java.util.UUID;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.json.JsonObject;

@ApplicationScoped
public class DummyUnifiedSearchIndexer implements UnifiedSearchIndexer {

@Inject
private IndexRepository indexRepository;

@Override
public void indexData(final JsonObject jsonObject) {
final UUID recipeId = fromString(jsonObject.getString("recipeId"));
final ZonedDateTime deliveryDate = ZonedDateTime.parse(jsonObject.getString("deliveryDate"));
final Index index = new Index(recipeId, deliveryDate);
indexRepository.save(index);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package uk.gov.justice.services.example.cakeshop.dummy;

import uk.gov.justice.services.unifiedsearch.UnifiedSearchIndexer;
import uk.gov.justice.services.unifiedsearch.UnifiedSearchName;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.inject.Inject;

@ApplicationScoped
public class DummyUnifiedSearchIndexerProducer {

@Inject
private DummyUnifiedSearchIndexer dummyUnifiedSearchIndexer;

@Produces
@UnifiedSearchName
public UnifiedSearchIndexer unifiedSearchClient(final InjectionPoint injectionPoint) {
return dummyUnifiedSearchIndexer;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="
http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd" bean-discovery-mode="all">
</beans>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"operations": [
{
"operation": "shift",
"spec": {
"cakeId": "cakeId",
"recipeId": "recipeId",
"deliveryDate": "deliveryDate"
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
event_sources:
- name: indexer.event.source
location:
jms_uri: jms:topic:example.event
rest_uri: http://localhost:8080/example/event-source-api/rest
data_source: java:/app/example-single/DS.eventstore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
subscriptions_descriptor:
spec_version: 1.0.0
service: example
service_component: EVENT_INDEXER
subscriptions:
- name: event indexer subscription
events:
- name: example.events.cake-ordered
schema_uri: http://justice.gov.uk/example/event/listener/example.events.cake-ordered.json
event_source_name: indexer.event.source


Loading

0 comments on commit e2117f2

Please sign in to comment.