Search in sources :

Example 61 with Subscription

use of org.candlepin.model.dto.Subscription in project candlepin by candlepin.

the class OwnerResourceTest method testUpdateOwner.

@Test
public void testUpdateOwner() {
    config.setProperty(ConfigProperties.STANDALONE, "false");
    Owner owner = new Owner("Test Owner", "test");
    ownerCurator.create(owner);
    Product prod1 = this.createProduct(owner);
    prod1.setAttribute(Product.Attributes.SUPPORT_LEVEL, "premium");
    productCurator.merge(prod1);
    Product prod2 = this.createProduct(owner);
    prod2.setAttribute(Product.Attributes.SUPPORT_LEVEL, "standard");
    productCurator.merge(prod2);
    List<Subscription> subscriptions = new LinkedList<>();
    ImportSubscriptionServiceAdapter subAdapter = new ImportSubscriptionServiceAdapter(subscriptions);
    OwnerServiceAdapter ownerAdapter = new DefaultOwnerServiceAdapter(this.ownerCurator, this.i18n);
    Subscription sub1 = TestUtil.createSubscription(owner, prod1, new HashSet<>());
    sub1.setId(Util.generateDbUUID());
    sub1.setQuantity(2000L);
    sub1.setStartDate(TestUtil.createDate(2010, 2, 9));
    sub1.setEndDate(TestUtil.createDate(3000, 2, 9));
    sub1.setModified(TestUtil.createDate(2010, 2, 12));
    subscriptions.add(sub1);
    Subscription sub2 = TestUtil.createSubscription(owner, prod2, new HashSet<>());
    sub2.setId(Util.generateDbUUID());
    sub2.setQuantity(2000L);
    sub2.setStartDate(TestUtil.createDate(2010, 2, 9));
    sub2.setEndDate(TestUtil.createDate(3000, 2, 9));
    sub2.setModified(TestUtil.createDate(2010, 2, 12));
    subscriptions.add(sub2);
    // Trigger the refresh:
    poolManager.getRefresher(subAdapter, ownerAdapter).add(owner).run();
    owner.setDefaultServiceLevel("premium");
    Owner parentOwner1 = ownerCurator.create(new Owner("Paren Owner 1", "parentTest1"));
    Owner parentOwner2 = ownerCurator.create(new Owner("Paren Owner 2", "parentTest2"));
    owner.setParentOwner(parentOwner1);
    ownerCurator.merge(owner);
    ownerCurator.flush();
    // Update with Display Name Only
    OwnerDTO dto = new OwnerDTO();
    dto.setDisplayName("New Name");
    ownerResource.updateOwner(owner.getKey(), dto);
    assertEquals("New Name", owner.getDisplayName());
    assertEquals(parentOwner1, owner.getParentOwner());
    assertEquals("premium", owner.getDefaultServiceLevel());
    assertFalse(owner.isAutobindDisabled());
    // Update with Default Service Level only
    dto = new OwnerDTO();
    dto.setDefaultServiceLevel("standard");
    ownerResource.updateOwner(owner.getKey(), dto);
    assertEquals("standard", owner.getDefaultServiceLevel());
    assertEquals("New Name", owner.getDisplayName());
    assertEquals(parentOwner1, owner.getParentOwner());
    assertFalse(owner.isAutobindDisabled());
    // Update with Parent Owner only
    OwnerDTO parentDto = new OwnerDTO();
    parentDto.setId(parentOwner2.getId());
    dto = new OwnerDTO();
    dto.setParentOwner(parentDto);
    ownerResource.updateOwner(owner.getKey(), dto);
    assertEquals(parentOwner2, owner.getParentOwner());
    assertEquals("standard", owner.getDefaultServiceLevel());
    assertEquals("New Name", owner.getDisplayName());
    assertFalse(owner.isAutobindDisabled());
    // Update with empty Service Level only
    dto = new OwnerDTO();
    dto.setDefaultServiceLevel("");
    ownerResource.updateOwner(owner.getKey(), dto);
    assertNull(owner.getDefaultServiceLevel());
    assertEquals("New Name", owner.getDisplayName());
    assertEquals(parentOwner2, owner.getParentOwner());
    assertFalse(owner.isAutobindDisabled());
    // Update autobind with disabled value.
    dto = new OwnerDTO();
    dto.setAutobindDisabled(true);
    ownerResource.updateOwner(owner.getKey(), dto);
    assertNull(owner.getDefaultServiceLevel());
    assertEquals("New Name", owner.getDisplayName());
    assertEquals(parentOwner2, owner.getParentOwner());
    assertTrue(owner.isAutobindDisabled());
    // Update autobind with enabled value.
    dto = new OwnerDTO();
    dto.setAutobindDisabled(false);
    ownerResource.updateOwner(owner.getKey(), dto);
    assertNull(owner.getDefaultServiceLevel());
    assertEquals("New Name", owner.getDisplayName());
    assertEquals(parentOwner2, owner.getParentOwner());
    assertFalse(owner.isAutobindDisabled());
    // Unset autobindDisabled results in no update.
    dto = new OwnerDTO();
    dto.setAutobindDisabled(null);
    ownerResource.updateOwner(owner.getKey(), dto);
    assertNull(owner.getDefaultServiceLevel());
    assertEquals("New Name", owner.getDisplayName());
    assertEquals(parentOwner2, owner.getParentOwner());
    assertFalse(owner.isAutobindDisabled());
}
Also used : Owner(org.candlepin.model.Owner) ImportSubscriptionServiceAdapter(org.candlepin.service.impl.ImportSubscriptionServiceAdapter) OwnerDTO(org.candlepin.dto.api.v1.OwnerDTO) OwnerServiceAdapter(org.candlepin.service.OwnerServiceAdapter) DefaultOwnerServiceAdapter(org.candlepin.service.impl.DefaultOwnerServiceAdapter) Product(org.candlepin.model.Product) Subscription(org.candlepin.model.dto.Subscription) LinkedList(java.util.LinkedList) DefaultOwnerServiceAdapter(org.candlepin.service.impl.DefaultOwnerServiceAdapter) Test(org.junit.Test)

Example 62 with Subscription

use of org.candlepin.model.dto.Subscription in project candlepin by candlepin.

the class ImporterTest method testRecordImportNoActiveSubsFound.

@Test
public void testRecordImportNoActiveSubsFound() {
    String expectedOwnerKey = "TEST_OWNER";
    Owner owner = new Owner(expectedOwnerKey);
    EventSink eventSinkMock = mock(EventSink.class);
    ImportRecordCurator importRecordCurator = mock(ImportRecordCurator.class);
    Importer importer = new Importer(null, null, null, null, null, null, null, null, config, null, null, eventSinkMock, i18n, null, null, su, importRecordCurator, this.mockSubReconciler, this.ec, this.translator);
    Map<String, Object> data = new HashMap<>();
    data.put("subscriptions", new ArrayList<Subscription>());
    ImportRecord record = importer.recordImportSuccess(owner, data, new ConflictOverrides(), "test.zip");
    assertEquals(ImportRecord.Status.SUCCESS_WITH_WARNING, record.getStatus());
    assertEquals(owner.getKey() + " file imported successfully." + "No active subscriptions found in the file.", record.getStatusMessage());
    verify(eventSinkMock, never()).emitSubscriptionExpired(any(Subscription.class));
    verify(importRecordCurator).create(eq(record));
}
Also used : Owner(org.candlepin.model.Owner) HashMap(java.util.HashMap) ImportRecordCurator(org.candlepin.model.ImportRecordCurator) EventSink(org.candlepin.audit.EventSink) Subscription(org.candlepin.model.dto.Subscription) ImportRecord(org.candlepin.model.ImportRecord) Test(org.junit.Test)

Example 63 with Subscription

use of org.candlepin.model.dto.Subscription in project candlepin by candlepin.

the class ImporterTest method testRecordImportExpiredSubsFound.

@Test
public void testRecordImportExpiredSubsFound() {
    String expectedOwnerKey = "TEST_OWNER";
    Owner owner = new Owner(expectedOwnerKey);
    EventSink eventSinkMock = mock(EventSink.class);
    ImportRecordCurator importRecordCurator = mock(ImportRecordCurator.class);
    Importer importer = new Importer(null, null, null, null, null, null, null, null, config, null, null, eventSinkMock, i18n, null, null, su, importRecordCurator, this.mockSubReconciler, this.ec, this.translator);
    Map<String, Object> data = new HashMap<>();
    List<Subscription> subscriptions = new ArrayList<>();
    Subscription subscription1 = new Subscription();
    // expires tomorrow
    subscription1.setEndDate(new Date((new Date()).getTime() + (1000 * 60 * 60 * 24)));
    subscriptions.add(subscription1);
    Subscription subscription2 = new Subscription();
    // expires yesterday
    subscription2.setEndDate(new Date((new Date()).getTime() - (1000 * 60 * 60 * 24)));
    subscriptions.add(subscription2);
    data.put("subscriptions", subscriptions);
    ImportRecord record = importer.recordImportSuccess(owner, data, new ConflictOverrides(), "test.zip");
    assertEquals(ImportRecord.Status.SUCCESS_WITH_WARNING, record.getStatus());
    assertEquals(owner.getKey() + " file imported successfully." + "One or more inactive subscriptions found in the file.", record.getStatusMessage());
    verify(eventSinkMock, never()).emitSubscriptionExpired(subscription1);
    verify(eventSinkMock).emitSubscriptionExpired(subscription2);
    verify(importRecordCurator).create(eq(record));
}
Also used : Owner(org.candlepin.model.Owner) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ImportRecord(org.candlepin.model.ImportRecord) Date(java.util.Date) ImportRecordCurator(org.candlepin.model.ImportRecordCurator) EventSink(org.candlepin.audit.EventSink) Subscription(org.candlepin.model.dto.Subscription) Test(org.junit.Test)

Example 64 with Subscription

use of org.candlepin.model.dto.Subscription in project candlepin by candlepin.

the class ImporterTest method testRecordImportSetsUpstreamConsumerFromOwner.

@Test
public void testRecordImportSetsUpstreamConsumerFromOwner() {
    String expectedOwnerKey = "TEST_OWNER";
    Owner owner = new Owner(expectedOwnerKey);
    UpstreamConsumer uc = new UpstreamConsumer("uc", owner, new ConsumerType(ConsumerType.ConsumerTypeEnum.CANDLEPIN), "uuid");
    uc.setContentAccessMode("mode");
    owner.setUpstreamConsumer(uc);
    EventSink eventSinkMock = mock(EventSink.class);
    ImportRecordCurator importRecordCurator = mock(ImportRecordCurator.class);
    Importer importer = new Importer(null, null, null, null, null, null, null, null, config, null, null, eventSinkMock, i18n, null, null, su, importRecordCurator, this.mockSubReconciler, this.ec, this.translator);
    Meta meta = new Meta("1.0", new Date(), "test-user", "candlepin", "testcdn");
    Map<String, Object> data = new HashMap<>();
    data.put("meta", meta);
    data.put("subscriptions", new ArrayList<Subscription>());
    ImportRecord record = importer.recordImportSuccess(owner, data, new ConflictOverrides(), "test.zip");
    ImportUpstreamConsumer iuc = record.getUpstreamConsumer();
    assertNotNull(iuc);
    assertEquals(uc.getOwnerId(), iuc.getOwnerId());
    assertEquals(uc.getName(), iuc.getName());
    assertEquals(uc.getUuid(), iuc.getUuid());
    assertEquals(uc.getType(), iuc.getType());
    assertEquals(uc.getWebUrl(), iuc.getWebUrl());
    assertEquals(uc.getApiUrl(), iuc.getApiUrl());
    assertEquals(uc.getContentAccessMode(), iuc.getContentAccessMode());
    verify(importRecordCurator).create(eq(record));
}
Also used : Owner(org.candlepin.model.Owner) HashMap(java.util.HashMap) ImportUpstreamConsumer(org.candlepin.model.ImportUpstreamConsumer) UpstreamConsumer(org.candlepin.model.UpstreamConsumer) ImportUpstreamConsumer(org.candlepin.model.ImportUpstreamConsumer) ImportRecord(org.candlepin.model.ImportRecord) Date(java.util.Date) ImportRecordCurator(org.candlepin.model.ImportRecordCurator) ConsumerType(org.candlepin.model.ConsumerType) EventSink(org.candlepin.audit.EventSink) Subscription(org.candlepin.model.dto.Subscription) Test(org.junit.Test)

Example 65 with Subscription

use of org.candlepin.model.dto.Subscription in project candlepin by candlepin.

the class SubscriptionReconcilerTest method testTwoExistThreeNewConsumer.

@Test
public void testTwoExistThreeNewConsumer() {
    Subscription testSub3 = createSubscription(owner, "test-prod-1", "up1", "ue3", "uc1", 15);
    Subscription testSub4 = createSubscription(owner, "test-prod-1", "up1", "ue4", "uc1", 10);
    Subscription testSub6 = createSubscription(owner, "test-prod-1", "up1", "ue6", "uc2", 15);
    Subscription testSub7 = createSubscription(owner, "test-prod-1", "up1", "ue7", "uc2", 10);
    Subscription testSub8 = createSubscription(owner, "test-prod-1", "up1", "ue8", "uc2", 5);
    createPoolsFor(testSub3, testSub4);
    reconciler.reconcile(owner, Arrays.asList(testSub6, testSub7, testSub8));
    assertUpstream(testSub6, testSub3.getId());
    assertUpstream(testSub7, testSub4.getId());
    assertUpstream(testSub8, testSub8.getId());
}
Also used : Subscription(org.candlepin.model.dto.Subscription) Test(org.junit.Test)

Aggregations

Subscription (org.candlepin.model.dto.Subscription)101 Test (org.junit.Test)77 Pool (org.candlepin.model.Pool)60 Product (org.candlepin.model.Product)48 SourceSubscription (org.candlepin.model.SourceSubscription)36 LinkedList (java.util.LinkedList)35 ArrayList (java.util.ArrayList)34 Owner (org.candlepin.model.Owner)33 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)27 HashMap (java.util.HashMap)20 HashSet (java.util.HashSet)18 Matchers.anyString (org.mockito.Matchers.anyString)18 Entitlement (org.candlepin.model.Entitlement)16 Date (java.util.Date)15 PoolType (org.candlepin.model.Pool.PoolType)13 ImportSubscriptionServiceAdapter (org.candlepin.service.impl.ImportSubscriptionServiceAdapter)13 List (java.util.List)11 OwnerServiceAdapter (org.candlepin.service.OwnerServiceAdapter)11 ConsumerType (org.candlepin.model.ConsumerType)10 ProductData (org.candlepin.model.dto.ProductData)9