Skip to content

Commit

Permalink
Merge c267f39 into de608ff
Browse files Browse the repository at this point in the history
  • Loading branch information
rladdusaw committed Sep 11, 2020
2 parents de608ff + c267f39 commit a71d83a
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 13 deletions.
32 changes: 30 additions & 2 deletions src/main/java/edu/tamu/app/model/Product.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.FetchType;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

import com.fasterxml.jackson.annotation.JsonView;

import edu.tamu.app.model.validation.ProductValidator;
Expand Down Expand Up @@ -48,6 +51,12 @@ public class Product extends ValidatingBaseEntity {
@JsonView(ApiView.Partial.class)
private String wikiUrl;

@LazyCollection(LazyCollectionOption.FALSE)
@ElementCollection
@JsonInclude(Include.NON_NULL)
@JsonView(ApiView.Partial.class)
private List<String> otherUrls;

@ElementCollection(fetch = FetchType.EAGER)
@JsonView(ApiView.Partial.class)
private List<RemoteProjectInfo> remoteProjectInfo;
Expand All @@ -68,7 +77,7 @@ public Product(String name, List<RemoteProjectInfo> remoteProjectInfo) {
this.remoteProjectInfo = remoteProjectInfo;
}

public Product(String name, List<RemoteProjectInfo> remoteProjectInfo, String scopeId, String devUrl, String preUrl, String productionUrl, String wikiUrl) {
public Product(String name, List<RemoteProjectInfo> remoteProjectInfo, String scopeId, String devUrl, String preUrl, String productionUrl, String wikiUrl, List<String> otherUrls) {
this();
this.name = name;
this.remoteProjectInfo = remoteProjectInfo;
Expand All @@ -77,6 +86,7 @@ public Product(String name, List<RemoteProjectInfo> remoteProjectInfo, String sc
this.preUrl = preUrl;
this.productionUrl = productionUrl;
this.wikiUrl = wikiUrl;
this.otherUrls = otherUrls;
}

public String getName() {
Expand Down Expand Up @@ -127,6 +137,24 @@ public void setWikiUrl(String wikiUrl) {
this.wikiUrl = wikiUrl;
}

public List<String> getOtherUrls() {
return otherUrls;
}

public void setOtherUrls(List<String> otherUrls) {
this.otherUrls = otherUrls;
}

public void addOtherUrl(String otherUrl) {
this.otherUrls.add(otherUrl);
}

public void removeOtherUrl(String otherUrl) {
this.otherUrls = this.otherUrls.stream()
.filter(o -> !o.equals(otherUrl))
.collect(Collectors.toList());
}

public List<RemoteProjectInfo> getRemoteProjectInfo() {
return remoteProjectInfo;
}
Expand Down
7 changes: 6 additions & 1 deletion src/test/java/edu/tamu/app/model/ModelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public abstract class ModelTest {
protected static final String TEST_INTERNAL_REQUEST_DESCRIPTION1 = "Test Internal Request Description 1";
protected static final String TEST_INTERNAL_REQUEST_DESCRIPTION2 = "Test Internal Request Description 2";

protected static final String TEST_OTHER_URL_1 = "Test Other URL 1";
protected static final String TEST_OTHER_URL_2 = "Test Other URL 2";

protected static final Date TEST_INTERNAL_REQUEST_CREATED_ON1 = new Date();
protected static final Date TEST_INTERNAL_REQUEST_CREATED_ON2 = new Date(System.currentTimeMillis() + 100);

Expand All @@ -51,7 +54,9 @@ public abstract class ModelTest {
protected static final List<RemoteProjectInfo> TEST_PRODUCT_REMOTE_PROJECT_INFO_LIST1 = new ArrayList<RemoteProjectInfo>(Arrays.asList(TEST_REMOTE_PROJECT_INFO1, TEST_REMOTE_PROJECT_INFO2));
protected static final List<RemoteProjectInfo> TEST_PRODUCT_REMOTE_PROJECT_INFO_LIST2 = new ArrayList<RemoteProjectInfo>(Arrays.asList(TEST_REMOTE_PROJECT_INFO3));

protected static final Product TEST_PRODUCT = new Product(TEST_PRODUCT_NAME, TEST_PRODUCT_REMOTE_PROJECT_INFO_LIST1);
protected static final List<String> TEST_OTHER_URLS = new ArrayList<String>(Arrays.asList(TEST_OTHER_URL_1, TEST_OTHER_URL_2));

protected static final Product TEST_PRODUCT = new Product(TEST_PRODUCT_NAME, TEST_PRODUCT_REMOTE_PROJECT_INFO_LIST1, TEST_PROJECT_SCOPE1, "", "", "", "", TEST_OTHER_URLS);

protected static final InternalRequest TEST_INTERNAL_REQUEST1 = new InternalRequest(TEST_INTERNAL_REQUEST_TITLE1, TEST_INTERNAL_REQUEST_DESCRIPTION1, TEST_PRODUCT, TEST_INTERNAL_REQUEST_CREATED_ON1);
protected static final InternalRequest TEST_INTERNAL_REQUEST2 = new InternalRequest(TEST_INTERNAL_REQUEST_TITLE2, TEST_INTERNAL_REQUEST_DESCRIPTION2, null, TEST_INTERNAL_REQUEST_CREATED_ON2);
Expand Down
44 changes: 34 additions & 10 deletions src/test/java/edu/tamu/app/model/ProductModelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import static org.junit.Assert.assertEquals;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.junit.Test;
Expand All @@ -26,31 +28,31 @@ public void testGetName() {

@Test
public void testGetScopeId() {
Product product = new Product(TEST_PRODUCT_NAME, TEST_PRODUCT_REMOTE_PROJECT_INFO_LIST1, TEST_PROJECT_SCOPE1, "", "", "", "");
Product product = new Product(TEST_PRODUCT_NAME, TEST_PRODUCT_REMOTE_PROJECT_INFO_LIST1, TEST_PROJECT_SCOPE1, "", "", "", "", null);
assertEquals("Product did not return the correct scope id!", TEST_PROJECT_SCOPE1, product.getScopeId());
}

@Test
public void testGetDevUri() {
Product product = new Product(TEST_PRODUCT_NAME, TEST_PRODUCT_REMOTE_PROJECT_INFO_LIST1, TEST_PROJECT_SCOPE1, TEST_URL_1, "", "", "");
Product product = new Product(TEST_PRODUCT_NAME, TEST_PRODUCT_REMOTE_PROJECT_INFO_LIST1, TEST_PROJECT_SCOPE1, TEST_URL_1, "", "", "", null);
assertEquals("Product did not return the correct dev URL!", TEST_URL_1, product.getDevUrl());
}

@Test
public void testGetPreUri() {
Product product = new Product(TEST_PRODUCT_NAME, TEST_PRODUCT_REMOTE_PROJECT_INFO_LIST1, TEST_PROJECT_SCOPE1, "", TEST_URL_1, "", "");
Product product = new Product(TEST_PRODUCT_NAME, TEST_PRODUCT_REMOTE_PROJECT_INFO_LIST1, TEST_PROJECT_SCOPE1, "", TEST_URL_1, "", "", null);
assertEquals("Product did not return the correct pre URL!", TEST_URL_1, product.getPreUrl());
}

@Test
public void testGetProductionUrl() {
Product product = new Product(TEST_PRODUCT_NAME, TEST_PRODUCT_REMOTE_PROJECT_INFO_LIST1, TEST_PROJECT_SCOPE1, "", "", TEST_URL_1, "");
Product product = new Product(TEST_PRODUCT_NAME, TEST_PRODUCT_REMOTE_PROJECT_INFO_LIST1, TEST_PROJECT_SCOPE1, "", "", TEST_URL_1, "", null);
assertEquals("Product did not return the correct production URL!", TEST_URL_1, product.getProductionUrl());
}

@Test
public void testGetWikiUrl() {
Product product = new Product(TEST_PRODUCT_NAME, TEST_PRODUCT_REMOTE_PROJECT_INFO_LIST1, TEST_PROJECT_SCOPE1, "", "", "", TEST_URL_1);
Product product = new Product(TEST_PRODUCT_NAME, TEST_PRODUCT_REMOTE_PROJECT_INFO_LIST1, TEST_PROJECT_SCOPE1, "", "", "", TEST_URL_1, null);
assertEquals("Product did not return the correct wiki URL!", TEST_URL_1, product.getWikiUrl());
}

Expand All @@ -69,35 +71,35 @@ public void testSetName() {

@Test
public void testSetDevUrl() {
Product product = new Product(TEST_PRODUCT_NAME, TEST_PRODUCT_REMOTE_PROJECT_INFO_LIST1, TEST_PROJECT_SCOPE1, TEST_URL_1, "", "", "");
Product product = new Product(TEST_PRODUCT_NAME, TEST_PRODUCT_REMOTE_PROJECT_INFO_LIST1, TEST_PROJECT_SCOPE1, TEST_URL_1, "", "", "", null);
product.setDevUrl(TEST_URL_2);
assertEquals("Product did not correctly update the dev URL!", TEST_URL_2, product.getDevUrl());
}

@Test
public void testSetPreUrl() {
Product product = new Product(TEST_PRODUCT_NAME, TEST_PRODUCT_REMOTE_PROJECT_INFO_LIST1, TEST_PROJECT_SCOPE1, "", TEST_URL_1, "", "");
Product product = new Product(TEST_PRODUCT_NAME, TEST_PRODUCT_REMOTE_PROJECT_INFO_LIST1, TEST_PROJECT_SCOPE1, "", TEST_URL_1, "", "", null);
product.setPreUrl(TEST_URL_2);
assertEquals("Product did not correctly update the pre URL!", TEST_URL_2, product.getPreUrl());
}

@Test
public void testSetProductionUrl() {
Product product = new Product(TEST_PRODUCT_NAME, TEST_PRODUCT_REMOTE_PROJECT_INFO_LIST1, TEST_PROJECT_SCOPE1, "", "", TEST_URL_1, "");
Product product = new Product(TEST_PRODUCT_NAME, TEST_PRODUCT_REMOTE_PROJECT_INFO_LIST1, TEST_PROJECT_SCOPE1, "", "", TEST_URL_1, "", null);
product.setProductionUrl(TEST_URL_2);
assertEquals("Product did not correctly update the production URL!", TEST_URL_2, product.getProductionUrl());
}

@Test
public void testSetWikiUrl() {
Product product = new Product(TEST_PRODUCT_NAME, TEST_PRODUCT_REMOTE_PROJECT_INFO_LIST1, TEST_PROJECT_SCOPE1, "", "", "", TEST_URL_1);
Product product = new Product(TEST_PRODUCT_NAME, TEST_PRODUCT_REMOTE_PROJECT_INFO_LIST1, TEST_PROJECT_SCOPE1, "", "", "", TEST_URL_1, null);
product.setWikiUrl(TEST_URL_2);
assertEquals("Product did not correctly update the Wiki URL!", TEST_URL_2, product.getWikiUrl());
}

@Test
public void testSetScopeId() {
Product product = new Product(TEST_PRODUCT_NAME, TEST_PRODUCT_REMOTE_PROJECT_INFO_LIST1, TEST_PROJECT_SCOPE1, "", "", "", "");
Product product = new Product(TEST_PRODUCT_NAME, TEST_PRODUCT_REMOTE_PROJECT_INFO_LIST1, TEST_PROJECT_SCOPE1, "", "", "", "", null);
product.setScopeId(TEST_PROJECT_SCOPE2);
assertEquals("Product did not correctly update the scope id!", TEST_PROJECT_SCOPE2, product.getScopeId());
}
Expand Down Expand Up @@ -125,4 +127,26 @@ public void testRemoveRemoteProduct() {
assertEquals("Product did not correctly add the remote project!", false, remoteProjectInfo.contains(TEST_REMOTE_PROJECT_INFO1));
}

@Test
public void testSetOtherUrls() {
Product product = new Product(TEST_PRODUCT_NAME, TEST_PRODUCT_REMOTE_PROJECT_INFO_LIST1);
product.setOtherUrls(TEST_OTHER_URLS);
assertEquals("Product did not correctly set the other URLs", 2, product.getOtherUrls().size());
}

@Test
public void testAddOtherUrl() {
Product product = new Product(TEST_PRODUCT_NAME, TEST_PRODUCT_REMOTE_PROJECT_INFO_LIST1, TEST_PROJECT_SCOPE1, "", "", "", "", new ArrayList<String>(Arrays.asList(TEST_OTHER_URL_1)));
product.addOtherUrl(TEST_OTHER_URL_2);
assertEquals("Product did not correctly add the second URL", 2, product.getOtherUrls().size());
}

@Test
public void testRemoveOtherUrl() {
Product product = new Product(TEST_PRODUCT_NAME, TEST_PRODUCT_REMOTE_PROJECT_INFO_LIST1, TEST_PROJECT_SCOPE1, "", "", "", "", TEST_OTHER_URLS);
product.removeOtherUrl(TEST_OTHER_URL_1);
assertEquals("Product did not remove other URL", 1, product.getOtherUrls().size());
assertEquals("Product did not remove correct other URL", TEST_OTHER_URL_2, product.getOtherUrls().get(0));
}

}
11 changes: 11 additions & 0 deletions src/test/java/edu/tamu/app/model/ProductTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,15 @@ public void testSetRemoteProductInfo() {
assertEquals("Product repo had incorrect number of products!", 0, productRepo.count());
}

@Test
public void testOtherUrlsCanBeSet() {
productRepo.create(TEST_PRODUCT);
Optional<Product> product = productRepo.findByName(TEST_PRODUCT_NAME);
assertTrue("Could not read product!", product.isPresent());
assertEquals("Product read did not have the correct name!", TEST_PRODUCT_NAME, product.get().getName());
assertEquals("Product did not have the expected other URLs", 2, product.get().getOtherUrls().size());
assertEquals("First other URL does not match", TEST_OTHER_URL_1, product.get().getOtherUrls().get(0));
assertEquals("Second other URL does not match", TEST_OTHER_URL_2, product.get().getOtherUrls().get(1));
}

}

0 comments on commit a71d83a

Please sign in to comment.