mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-19 14:05:50 +00:00
Merge conflicts
This commit is contained in:
commit
0fdde05b30
3 changed files with 30 additions and 19 deletions
|
@ -78,6 +78,7 @@ public class NewOwnerStore {
|
||||||
if(iterator.hasNext()) {
|
if(iterator.hasNext()) {
|
||||||
Owner oldOwner = iterator.next();
|
Owner oldOwner = iterator.next();
|
||||||
if(id != oldOwner.getId() || !ownerStore.get(id).equals(oldOwner)) {
|
if(id != oldOwner.getId() || !ownerStore.get(id).equals(oldOwner)) {
|
||||||
|
ownerStore.put(id, StaticOwner.convertToStaticOwner(oldOwner));
|
||||||
inconsistencies++;
|
inconsistencies++;
|
||||||
violation(id, StaticOwner.convertToStaticOwner(oldOwner), ownerStore.get(id));
|
violation(id, StaticOwner.convertToStaticOwner(oldOwner), ownerStore.get(id));
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,6 +105,7 @@ class OwnerController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@GetMapping("/owners/{ownerId}/edit")
|
@GetMapping("/owners/{ownerId}/edit")
|
||||||
public String initUpdateOwnerForm(@PathVariable("ownerId") int ownerId, Model model) {
|
public String initUpdateOwnerForm(@PathVariable("ownerId") int ownerId, Model model) {
|
||||||
Owner owner = this.owners.findById(ownerId);
|
Owner owner = this.owners.findById(ownerId);
|
||||||
|
|
|
@ -7,13 +7,12 @@ package org.springframework.samples.petclinic.newDataStore;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Map;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
|
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
|
||||||
import org.springframework.samples.petclinic.owner.Owner;
|
import org.springframework.samples.petclinic.owner.Owner;
|
||||||
|
@ -22,6 +21,8 @@ import org.springframework.samples.petclinic.owner.StaticOwner;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
import static org.mockito.BDDMockito.given;
|
||||||
|
import static org.mockito.Mockito.doReturn;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Gibran
|
* @author Gibran
|
||||||
|
@ -30,22 +31,30 @@ import static org.junit.Assert.*;
|
||||||
@DataJpaTest
|
@DataJpaTest
|
||||||
public class NewOwnerStoreTest {
|
public class NewOwnerStoreTest {
|
||||||
|
|
||||||
|
private static final int TEST_OWNER_ID = 1;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
OwnerRepository owners;
|
OwnerRepository ownerRepository;
|
||||||
|
|
||||||
NewOwnerStore testOwnerStore;
|
NewOwnerStore testOwnerStore;
|
||||||
|
|
||||||
HashMap<Integer, StaticOwner> ownerStore;
|
Map<Integer, StaticOwner> ownerStore;
|
||||||
|
|
||||||
|
Owner owner;
|
||||||
@Mock
|
|
||||||
Owner mockOwner;
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
testOwnerStore = NewOwnerStore.getInstance(owners);
|
testOwnerStore = NewOwnerStore.getInstance(ownerRepository);
|
||||||
testOwnerStore.forklift();
|
testOwnerStore.forklift();
|
||||||
ownerStore = testOwnerStore.getStore();
|
ownerStore = testOwnerStore.getStore();
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
doReturn(TEST_OWNER_ID).when(owner).getId();
|
||||||
|
doReturn("John").when(owner).getFirstName();
|
||||||
|
doReturn("Doe").when(owner).getLastName();
|
||||||
|
doReturn("123 Cucumber Lane").when(owner).getAddress();
|
||||||
|
doReturn("Placeville").when(owner).getCity();
|
||||||
|
doReturn("1234567890").when(owner).getTelephone();
|
||||||
|
given(this.ownerRepository.findById(TEST_OWNER_ID)).willReturn(owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -60,10 +69,10 @@ public class NewOwnerStoreTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testShadowRead() {
|
public void testShadowRead() {
|
||||||
testOwnerStore = NewOwnerStore.getInstance(owners);
|
testOwnerStore = NewOwnerStore.getInstance(ownerRepository);
|
||||||
testOwnerStore.forklift();
|
testOwnerStore.forklift();
|
||||||
|
|
||||||
Collection<Owner> results = this.owners.findByLastName("");
|
Collection<Owner> results = this.ownerRepository.findByLastName("");
|
||||||
|
|
||||||
int inconsistencies = compareResults(results, "");
|
int inconsistencies = compareResults(results, "");
|
||||||
|
|
||||||
|
@ -124,16 +133,16 @@ public class NewOwnerStoreTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void checkShadowWrite() {
|
public void testShadowWrite() {
|
||||||
testOwnerStore = NewOwnerStore.getInstance(owners);
|
testOwnerStore = NewOwnerStore.getInstance(ownerRepository);
|
||||||
|
|
||||||
//make sure that inconsisties are recorded and fixed
|
//make sure that inconsistencies are recorded and fixed
|
||||||
testOwnerStore.testPutInOldDatastoreOnly(mockOwner);
|
testOwnerStore.testPutInOldDatastoreOnly(owner);
|
||||||
assertEquals(1, testOwnerStore.checkConsistency());
|
assertEquals(1, testOwnerStore.checkConsistency());
|
||||||
assertEquals(0, testOwnerStore.checkConsistency());
|
assertEquals(0, testOwnerStore.checkConsistency());
|
||||||
|
|
||||||
//make sure that any changes written to old database are also written to new database
|
//make sure that any changes written to old database are also written to new database
|
||||||
testOwnerStore.save(mockOwner);
|
testOwnerStore.save(owner);
|
||||||
assertEquals(0, testOwnerStore.checkConsistency());
|
assertEquals(0, testOwnerStore.checkConsistency());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue