Merge branch 'bug5841'

This commit is contained in:
Axel Uhl
2023-05-05 23:36:24 +02:00
13 changed files with 187 additions and 18 deletions
@@ -91,7 +91,7 @@ public abstract class AbstractSubscriptionActivity extends AbstractActivity impl
} else {
groupDTO = new SubscriptionGroupDTO(plan.getGroup().getId(),
plan.isUserSubscribedToPlan(), plan.getPrices(), plan.getGroup(),
plan.isUserSubscribedToPlanCategory(), plan.getError(), type);
plan.isUserSubscribedToAllPlanCategories(), plan.getError(), type);
groupMap.put(plan.getGroup(), groupDTO);
}
});
@@ -147,7 +147,7 @@ public abstract class AbstractSubscriptionActivity extends AbstractActivity impl
}
private boolean checkIfUserIsSubscribedToPlanCategory(final SubscriptionPlanDTO plan) {
return plan.isUserSubscribedToPlanCategory();
return plan.isUserSubscribedToAllPlanCategories();
}
private boolean checkIfUserWasAlreadySubscripedToOneTimePlan(final SubscriptionPlanDTO plan) {
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src">
<attributes>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin"/>
</classpath>
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>com.sap.sse.security.ui.test</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
@@ -0,0 +1,8 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
@@ -0,0 +1,3 @@
eclipse.preferences.version=1
pluginProject.extensions=false
resolve.requirebundle=false
@@ -0,0 +1,16 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Test
Bundle-SymbolicName: com.sap.sse.security.ui.test
Bundle-Version: 1.0.0.qualifier
Bundle-Vendor: SAP
Fragment-Host: com.sap.sse.security.ui
Import-Package: net.bytebuddy;version="1.12.18",
net.bytebuddy.agent;version="1.12.18",
org.junit,
org.mockito;version="4.8.1",
org.mockito.stubbing;version="4.8.1",
org.objenesis;version="3.3.0"
Require-Bundle: com.sap.sailing.domain.common
Automatic-Module-Name: com.sap.sse.security.ui.test
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
@@ -0,0 +1,4 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
+12
View File
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>root</artifactId>
<groupId>com.sap.sailing</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>com.sap.sse.security.ui.test</artifactId>
<packaging>eclipse-test-plugin</packaging>
</project>
@@ -0,0 +1,79 @@
package com.sap.sse.security.ui.server.subscription;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.junit.Before;
import org.junit.Test;
import com.sap.sailing.domain.common.subscription.SailingSubscriptionPlan;
import com.sap.sse.common.TimePoint;
import com.sap.sse.security.SecurityService;
import com.sap.sse.security.shared.impl.User;
import com.sap.sse.security.shared.subscription.Subscription;
import com.sap.sse.security.shared.subscription.SubscriptionPlan;
import com.sap.sse.security.shared.subscription.chargebee.ChargebeeSubscription;
import com.sap.sse.security.ui.server.subscription.chargebee.ChargebeeSubscriptionWriteServiceImpl;
import com.sap.sse.security.ui.shared.subscription.SubscriptionPlanDTO;
public class TestPlanSubscriptionRules {
private final SubscriptionPlan dataMiningArchiveYearly = SailingSubscriptionPlan.DATA_MINING_ARCHIVE_YEARLY;
private final SubscriptionPlan premiumYearly = SailingSubscriptionPlan.PREMIUM_YEARLY;
private User user;
private Subscription premiumYearlySubscription;
private Subscription dataMiningArchiveYearlySubscription;
private SecurityService securityService;
private ChargebeeSubscriptionWriteServiceImpl service;
@Before
public void setUp() {
user = mock(User.class);
premiumYearlySubscription = new ChargebeeSubscription("subscriptionId1", premiumYearly.getId(), "customerId",
TimePoint.now(), TimePoint.now(), /* subscriptionStatus */ "active", /* paymentStatus */ "paid", "transactionType", "transactionStatus", "invoiceId",
"invoiceStatus", /* reoccuringPaymentValue */ 49, /* currencyCode */ "USD", TimePoint.now(), TimePoint.now(),
TimePoint.now(), TimePoint.now(), TimePoint.now(), /* cancelledAt */ null, TimePoint.now(), /* manualUpdatedAt */ null);
dataMiningArchiveYearlySubscription = new ChargebeeSubscription("subscriptionId2", dataMiningArchiveYearly.getId(), "customerId",
TimePoint.now(), TimePoint.now(), /* subscriptionStatus */ "active", /* paymentStatus */ "paid", "transactionType", "transactionStatus", "invoiceId",
"invoiceStatus", /* reoccuringPaymentValue */ 49, /* currencyCode */ "USD", TimePoint.now(), TimePoint.now(),
TimePoint.now(), TimePoint.now(), TimePoint.now(), /* cancelledAt */ null, TimePoint.now(), /* manualUpdatedAt */ null);
securityService = mock(SecurityService.class);
when(securityService.getAllSubscriptionPlans()).thenReturn(SailingSubscriptionPlan.getAllInstances());
service = new ChargebeeSubscriptionWriteServiceImpl() {
private static final long serialVersionUID = 1L;
@Override
protected User getCurrentUser() {
return user;
}
@Override
protected SecurityService getSecurityService() {
return securityService;
}
};
}
@Test
public void testThatPemiumDoesNotImplyDataMiningByCategory() {
when(user.getSubscriptionByPlan(premiumYearly.getId())).thenReturn(premiumYearlySubscription);
final SubscriptionPlanDTO premiumYearlyDTO = service.convertToDto(premiumYearly);
final SubscriptionPlanDTO dataMiningArchiveYearlyDTO = service.convertToDto(dataMiningArchiveYearly);
assertTrue(premiumYearlyDTO.isUserSubscribedToPlan());
assertTrue(premiumYearlyDTO.isUserSubscribedToAllPlanCategories());
assertFalse(dataMiningArchiveYearlyDTO.isUserSubscribedToPlan());
assertFalse(dataMiningArchiveYearlyDTO.isUserSubscribedToAllPlanCategories());
}
@Test
public void testThatDataMiningImpliesPemiumByCategory() {
when(user.getSubscriptionByPlan(dataMiningArchiveYearly.getId())).thenReturn(dataMiningArchiveYearlySubscription);
final SubscriptionPlanDTO premiumYearlyDTO = service.convertToDto(premiumYearly);
final SubscriptionPlanDTO dataMiningArchiveYearlyDTO = service.convertToDto(dataMiningArchiveYearly);
assertFalse(premiumYearlyDTO.isUserSubscribedToPlan());
assertTrue(premiumYearlyDTO.isUserSubscribedToAllPlanCategories());
assertTrue(dataMiningArchiveYearlyDTO.isUserSubscribedToPlan());
assertTrue(dataMiningArchiveYearlyDTO.isUserSubscribedToAllPlanCategories());
}
}
@@ -36,6 +36,7 @@ import com.sap.sse.security.shared.impl.Role;
import com.sap.sse.security.shared.impl.User;
import com.sap.sse.security.shared.subscription.Subscription;
import com.sap.sse.security.shared.subscription.SubscriptionPlan;
import com.sap.sse.security.shared.subscription.SubscriptionPlan.PlanCategory;
import com.sap.sse.security.shared.subscription.SubscriptionPrice;
import com.sap.sse.security.subscription.SubscriptionApiService;
import com.sap.sse.security.ui.client.subscription.SubscriptionService;
@@ -218,34 +219,38 @@ public abstract class SubscriptionServiceImpl extends RemoteServiceServlet imple
protected SubscriptionPlanDTO convertToDto(SubscriptionPlan plan) {
final boolean isUserSubscribedToPlan = isUserSubscribedToPlan(plan.getId());
boolean isUserSubscribedToPlanCategory = false;
boolean isUserSubscribedToAllPlanCategories = false;
boolean hasHadSubscriptionForOneTimePlan;
if(isUserSubscribedToPlan) {
isUserSubscribedToPlanCategory = true;
if (isUserSubscribedToPlan) {
isUserSubscribedToAllPlanCategories = true;
hasHadSubscriptionForOneTimePlan = plan.getIsOneTimePlan();
} else {
final Set<PlanCategory> categoriesRequired = new HashSet<>(plan.getPlanCategories());
for (SubscriptionPlan subscriptionPlan : getSecurityService().getAllSubscriptionPlans().values()) {
if(isUserSubscribedToPlan(subscriptionPlan.getId())
&& Util.containsAny(plan.getPlanCategories(), subscriptionPlan.getPlanCategories())) {
isUserSubscribedToPlanCategory = true;
break;
if (isUserSubscribedToPlan(subscriptionPlan.getId())) {
categoriesRequired.removeAll(subscriptionPlan.getPlanCategories());
if (categoriesRequired.isEmpty()) {
isUserSubscribedToAllPlanCategories = true;
break;
}
}
}
try {
final User currentUser = getCurrentUser();
hasHadSubscriptionForOneTimePlan = currentUser.hasAnySubscription(plan.getId()) && plan.getIsOneTimePlan();
hasHadSubscriptionForOneTimePlan = currentUser.hasAnySubscription(plan.getId())
&& plan.getIsOneTimePlan();
} catch (UserManagementException e) {
hasHadSubscriptionForOneTimePlan = false;
}
}
final boolean disablePrice = hasHadSubscriptionForOneTimePlan;
Set<SubscriptionPrice> prices = new HashSet<>();
final Set<SubscriptionPrice> prices = new HashSet<>();
plan.getPrices().forEach(price -> {
price.setDisablePlan(disablePrice);
prices.add(price);
});
return new SubscriptionPlanDTO(plan.getId(), isUserSubscribedToPlan, prices,
plan.getPlanCategories(), hasHadSubscriptionForOneTimePlan, isUserSubscribedToPlanCategory, null, plan.getGroup());
return new SubscriptionPlanDTO(plan.getId(), isUserSubscribedToPlan, prices, plan.getPlanCategories(),
hasHadSubscriptionForOneTimePlan, isUserSubscribedToAllPlanCategories, null, plan.getGroup());
}
private boolean isUserSubscribedToPlan(String planId) {
@@ -20,7 +20,7 @@ public class SubscriptionPlanDTO implements HasSubscriptionMessageKeys, IsSerial
private Boolean isUserSubscribedToPlan;
private Set<PlanCategory> planCategory;
private Boolean userWasAlreadySubscribedToOneTimePlan;
private Boolean isUserSubscribedToPlanCategory;
private Boolean isUserSubscribedToAllPlanCategories;
private PlanGroup group;
/**
@@ -32,12 +32,12 @@ public class SubscriptionPlanDTO implements HasSubscriptionMessageKeys, IsSerial
public SubscriptionPlanDTO(String id, boolean isUserSubscribedToPlan, Set<SubscriptionPrice> prices,
Set<PlanCategory> planCategory, boolean userWasAlreadySubscribedToOneTimePlan,
boolean isUserSubscribedToPlanCategory, String error, PlanGroup group) {
boolean isUserSubscribedToAllPlanCategories, String error, PlanGroup group) {
this.id = id;
this.isUserSubscribedToPlan = isUserSubscribedToPlan;
this.planCategory = planCategory;
this.userWasAlreadySubscribedToOneTimePlan = userWasAlreadySubscribedToOneTimePlan;
this.isUserSubscribedToPlanCategory = isUserSubscribedToPlanCategory;
this.isUserSubscribedToAllPlanCategories = isUserSubscribedToAllPlanCategories;
this.prices = new HashSet<SubscriptionPrice>(prices);
this.error = error;
this.group = group;
@@ -81,8 +81,8 @@ public class SubscriptionPlanDTO implements HasSubscriptionMessageKeys, IsSerial
return prices;
}
public boolean isUserSubscribedToPlanCategory() {
return isUserSubscribedToPlanCategory;
public boolean isUserSubscribedToAllPlanCategories() {
return isUserSubscribedToAllPlanCategories;
}
public void setError(String error) {
+1
View File
@@ -119,6 +119,7 @@
<module>com.sap.sse.security.storemerging</module>
<module>com.sap.sse.security.storemerging.test</module>
<module>com.sap.sse.security.ui</module>
<module>com.sap.sse.security.ui.test</module>
<module>com.sap.sse.security.userstore.mongodb</module>
<module>com.sap.sse.operationaltransformation</module>
<module>com.sap.sse.replication</module>