Skip to content
This repository has been archived by the owner on Apr 15, 2021. It is now read-only.

Commit

Permalink
Merge the current master to GitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
redmond2683 committed Jan 26, 2016
1 parent d6bf739 commit 8a4a5a5
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
import org.oscm.domobjects.TechnicalProductOperation;
import org.oscm.domobjects.enums.LocalizedObjectTypes;
import org.oscm.i18nservice.bean.LocalizerFacade;
import org.oscm.serviceprovisioningservice.assembler.ProductAssembler;
import org.oscm.internal.landingpage.POLandingpageEntry;
import org.oscm.internal.types.enumtypes.OrganizationRoleType;
import org.oscm.internal.types.enumtypes.ServiceType;
import org.oscm.serviceprovisioningservice.assembler.ProductAssembler;

/**
* Assembler that merges service and subscription into PO object
Expand Down Expand Up @@ -142,8 +142,8 @@ protected static void updateEntryForSubscription(Subscription subscription,
entry.setSubscribed(true);
}

static void setServiceAccessUrl(Subscription subscription, POLandingpageEntry entry,
TechnicalProduct techProd) {
static void setServiceAccessUrl(Subscription subscription,
POLandingpageEntry entry, TechnicalProduct techProd) {
if (subscription.getBaseURL() == null) {
entry.setServiceAccessURL(techProd.getBaseURL());
} else {
Expand Down Expand Up @@ -178,7 +178,7 @@ private static void prefetchForPoducts(List<Product> products,
LocalizerFacade facade) {
List<Long> objectKeys = new ArrayList<Long>();
for (Product product : products) {
objectKeys.add(Long.valueOf(product.getKey()));
objectKeys.add(Long.valueOf(product.getTemplateOrSelf().getKey()));
}
facade.prefetch(
objectKeys,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,40 @@

package org.oscm.internal.assembler;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.oscm.test.Numbers.L_TIMESTAMP;
import static org.oscm.test.matchers.JavaMatchers.hasNoItems;
import static org.oscm.test.matchers.JavaMatchers.hasOneItem;
import static org.oscm.test.matchers.JavaMatchers.isNullValue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

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

import org.junit.Before;
import org.junit.Test;

import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Matchers;
import org.mockito.MockitoAnnotations;
import org.oscm.domobjects.Organization;
import org.oscm.domobjects.PlatformUser;
import org.oscm.domobjects.Product;
import org.oscm.domobjects.Subscription;
import org.oscm.domobjects.TechnicalProduct;
import org.oscm.domobjects.enums.LocalizedObjectTypes;
import org.oscm.i18nservice.bean.LocalizerFacade;
import org.oscm.test.stubs.LocalizerServiceStub;
import org.oscm.internal.landingpage.POLandingpageEntry;
import org.oscm.internal.types.enumtypes.ServiceAccessType;
import org.oscm.internal.types.enumtypes.ServiceStatus;
import org.oscm.internal.types.enumtypes.ServiceType;
import org.oscm.internal.types.enumtypes.SubscriptionStatus;
import org.oscm.test.stubs.LocalizerServiceStub;

/**
* @author zankov
Expand All @@ -44,6 +50,8 @@
public class POLandingpageEntryAssemblerTest {

private LocalizerFacade facade;
@Captor
ArgumentCaptor<List<Long>> objectKeyCaptor;

@Before
public void setup() throws Exception {
Expand All @@ -55,6 +63,8 @@ public String getLocalizedTextFromDatabase(String localeString,
return objectType.name();
}
}, "en");

MockitoAnnotations.initMocks(this);
}

private Organization givenSupplier() {
Expand Down Expand Up @@ -261,4 +271,69 @@ private Subscription givenSubscription(String subId, ServiceAccessType type) {
subscription.setOwner(owner);
return subscription;
}

@Test
public void toPOLandingpageEntries_prefetchForPoducts_withoutTemplates_bug12479() {
// given
List<Subscription> subscriptions = Arrays.asList(
givenSubscription("sub_1", ServiceAccessType.LOGIN),
givenSubscription("sub_2", ServiceAccessType.LOGIN));
List<Product> services = Arrays
.asList(givenProduct(ServiceAccessType.LOGIN));
LocalizerFacade facadeMock = spy(facade);

// when
POLandingpageEntryAssembler.toPOLandingpageEntries(services,
subscriptions, facadeMock);

// than
verify(facadeMock, times(2)).prefetch(objectKeyCaptor.capture(),
Matchers.anyListOf(LocalizedObjectTypes.class));
List<List<Long>> args = objectKeyCaptor.getAllValues();
List<Long> objectkeys = args.get(0);
assertEquals(1, objectkeys.size());
assertEquals(Long.valueOf(4321), objectkeys.get(0));
}

@Test
public void toPOLandingpageEntries_prefetchForPoducts_withTemplates_bug12479() {
// given
List<Subscription> subscriptions = Arrays.asList(
givenSubscription("sub_1", ServiceAccessType.LOGIN),
givenSubscription("sub_2", ServiceAccessType.LOGIN));
List<Product> services = new ArrayList<Product>();
services.add(givenProduct(ServiceAccessType.LOGIN));
Product template = new Product();
template.setType(ServiceType.TEMPLATE);
template.setVendor(givenSupplier());
template.setTechnicalProduct(givenTechnicalProduct(ServiceAccessType.LOGIN));
template.setKey(4322);
template.setProductId("template");
template.setStatus(ServiceStatus.ACTIVE);
services.add(template);
Product product = new Product();
product.setType(ServiceType.TEMPLATE);
product.setVendor(givenSupplier());
product.setTechnicalProduct(givenTechnicalProduct(ServiceAccessType.LOGIN));
product.setKey(4323);
product.setProductId("product");
product.setStatus(ServiceStatus.ACTIVE);
product.setTemplate(template);
services.add(product);
LocalizerFacade facadeMock = spy(facade);

// when
POLandingpageEntryAssembler.toPOLandingpageEntries(services,
subscriptions, facadeMock);

// than
verify(facadeMock, times(2)).prefetch(objectKeyCaptor.capture(),
Matchers.anyListOf(LocalizedObjectTypes.class));
List<List<Long>> args = objectKeyCaptor.getAllValues();
List<Long> objectkeys = args.get(0);
assertEquals(3, objectkeys.size());
assertEquals(Long.valueOf(4321), objectkeys.get(0));
assertEquals(Long.valueOf(4322), objectkeys.get(1));
assertEquals(Long.valueOf(4322), objectkeys.get(2));
}
}
2 changes: 1 addition & 1 deletion oscm-portal-webtests/tests/marketplace/allTests.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<ant antfile="./marketplace/testTags.xml" />
<ant antfile="./marketplace/testPaging.xml" />
<ant antfile="./marketplace/testConfigurableMarketplaces.xml" />
<ant antfile="./marketplace/testServiceVisibility.xml" />
<!-- <ant antfile="./marketplace/testServiceVisibility.xml" /> -->
<ant antfile="./marketplace/testFeedbackRating.xml" />
<ant antfile="./marketplace/testSingleSubscription.xml" />
<ant antfile="./marketplace/testSubscriptionDetail.xml" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
import org.oscm.domobjects.enums.LocalizedObjectTypes;
import org.oscm.i18nservice.bean.LocalizerFacade;
import org.oscm.interceptor.DateFactory;
import org.oscm.validator.BLValidator;
import org.oscm.vo.BaseAssembler;
import org.oscm.internal.types.enumtypes.OfferingType;
import org.oscm.internal.types.enumtypes.OrganizationRoleType;
import org.oscm.internal.types.enumtypes.PerformanceHint;
Expand All @@ -48,6 +46,8 @@
import org.oscm.internal.vo.VOServiceDetails;
import org.oscm.internal.vo.VOServiceEntry;
import org.oscm.internal.vo.VOTechnicalService;
import org.oscm.validator.BLValidator;
import org.oscm.vo.BaseAssembler;

/**
* @author G&uuml;nther Schmid
Expand Down Expand Up @@ -270,7 +270,8 @@ public static void prefetchData(List<Product> products,
if (scope == PerformanceHint.ONLY_FIELDS_FOR_LISTINGS) {
List<Long> objectKeys = new ArrayList<Long>();
for (Product product : products) {
objectKeys.add(Long.valueOf(product.getKey()));
objectKeys.add(Long.valueOf(product.getTemplateOrSelf()
.getKey()));
}
facade.prefetch(
objectKeys,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import java.math.BigDecimal;
import java.util.ArrayList;
Expand All @@ -27,7 +30,10 @@
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Matchers;
import org.mockito.MockitoAnnotations;
import org.oscm.domobjects.Event;
import org.oscm.domobjects.Organization;
import org.oscm.domobjects.OrganizationRole;
Expand All @@ -47,7 +53,6 @@
import org.oscm.domobjects.TechnicalProductTag;
import org.oscm.domobjects.enums.LocalizedObjectTypes;
import org.oscm.i18nservice.bean.LocalizerFacade;
import org.oscm.test.stubs.LocalizerServiceStub;
import org.oscm.internal.types.enumtypes.OrganizationRoleType;
import org.oscm.internal.types.enumtypes.PerformanceHint;
import org.oscm.internal.types.enumtypes.PriceModelType;
Expand All @@ -60,6 +65,7 @@
import org.oscm.internal.vo.VOPricedParameter;
import org.oscm.internal.vo.VOService;
import org.oscm.internal.vo.VOServiceDetails;
import org.oscm.test.stubs.LocalizerServiceStub;

/**
* @author weiser
Expand All @@ -78,17 +84,24 @@ public class ProductAssemblerTest {
private PlatformUser user;
private VOService voService;
private VOService voCustomerService;
@Captor
ArgumentCaptor<List<Long>> objectKeyCaptor;

@Before
public void setup() throws Exception {

facade = new LocalizerFacade(new LocalizerServiceStub() {

@Override
public String getLocalizedTextFromDatabase(String localeString,
long objectKey, LocalizedObjectTypes objectType) {

return objectType.name();
}
}, "en");

MockitoAnnotations.initMocks(this);

technicalProduct = new TechnicalProduct();
technicalProduct.setAccessType(ServiceAccessType.DIRECT);
technicalProduct.setBaseURL("baseURL");
Expand Down Expand Up @@ -810,4 +823,51 @@ private void verifyCopiedAttributes(Product prod) {
Boolean.valueOf(voService.isAutoAssignUserEnabled()));
}

@Test
public void prefetchData_withoutTemplates_bug12479() {
// given
List<Product> products = new ArrayList<Product>();
products.add(product);
products.add(customerProduct);
LocalizerFacade facadeMock = spy(facade);

// when
ProductAssembler.prefetchData(products, facadeMock,
PerformanceHint.ONLY_FIELDS_FOR_LISTINGS);

// then
verify(facadeMock, times(1)).prefetch(objectKeyCaptor.capture(),
Matchers.anyListOf(LocalizedObjectTypes.class));
List<Long> objectkeys = objectKeyCaptor.getValue();
assertEquals(2, objectkeys.size());
assertEquals(Long.valueOf(product.getKey()), objectkeys.get(0));
assertEquals(Long.valueOf(customerProduct.getKey()), objectkeys.get(1));
}

@Test
public void prefetchData_withTemplates_bug12479() {
// given
List<Product> products = new ArrayList<Product>();
products.add(product);
Product anotherProduct = new Product();
anotherProduct.setType(ServiceType.PARTNER_TEMPLATE);
anotherProduct.setConfiguratorUrl("some value");
anotherProduct.setTemplate(template);
products.add(anotherProduct);
products.add(customerProduct);
LocalizerFacade facadeMock = spy(facade);

// when
ProductAssembler.prefetchData(products, facadeMock,
PerformanceHint.ONLY_FIELDS_FOR_LISTINGS);

// then
verify(facadeMock, times(1)).prefetch(objectKeyCaptor.capture(),
Matchers.anyListOf(LocalizedObjectTypes.class));
List<Long> objectkeys = objectKeyCaptor.getValue();
assertEquals(3, objectkeys.size());
assertEquals(Long.valueOf(product.getKey()), objectkeys.get(0));
assertEquals(Long.valueOf(template.getKey()), objectkeys.get(1));
assertEquals(Long.valueOf(customerProduct.getKey()), objectkeys.get(2));
}
}

0 comments on commit 8a4a5a5

Please sign in to comment.