Exemplo n.º 1
0
 @Test(expected = BadRequestException.class)
 public void testFetchAllConsumersForEmptyUUIDs() {
   ConsumerResource cr =
       new ConsumerResource(
           mockedConsumerCurator,
           null,
           null,
           null,
           null,
           null,
           null,
           i18n,
           null,
           null,
           null,
           null,
           null,
           null,
           null,
           null,
           null,
           null,
           null,
           null,
           null,
           null,
           new CandlepinCommonTestConfig(),
           null,
           null,
           null,
           null,
           productCurator,
           null);
   List<Consumer> result = cr.list(null, null, null, new ArrayList<String>(), null, null, null);
 }
Exemplo n.º 2
0
 @Test(expected = BadRequestException.class)
 public void testFetchAllConsumers() {
   ConsumerResource cr =
       new ConsumerResource(
           null,
           null,
           null,
           null,
           null,
           null,
           null,
           i18n,
           null,
           null,
           null,
           null,
           null,
           null,
           null,
           null,
           null,
           null,
           null,
           null,
           null,
           null,
           new CandlepinCommonTestConfig(),
           null,
           null,
           null,
           null,
           productCurator,
           null);
   cr.list(null, null, null, null, null, null, null);
 }
Exemplo n.º 3
0
  @Test
  public void testIdCertGetsRegenerated() throws Exception {
    // using lconsumer simply to avoid hiding consumer. This should
    // get renamed once we refactor this test suite.
    IdentityCertServiceAdapter mockedIdSvc = Mockito.mock(IdentityCertServiceAdapter.class);

    EventSink sink = Mockito.mock(EventSinkImpl.class);

    SubscriptionServiceAdapter ssa = Mockito.mock(SubscriptionServiceAdapter.class);
    ComplianceRules rules = Mockito.mock(ComplianceRules.class);

    Consumer consumer = createConsumer();
    ComplianceStatus status = new ComplianceStatus();
    when(rules.getStatus(any(Consumer.class), any(Date.class), anyBoolean())).thenReturn(status);
    // cert expires today which will trigger regen
    consumer.setIdCert(createIdCert());
    BigInteger origserial = consumer.getIdCert().getSerial().getSerial();

    when(mockedConsumerCurator.verifyAndLookupConsumer(consumer.getUuid())).thenReturn(consumer);
    when(mockedIdSvc.regenerateIdentityCert(consumer)).thenReturn(createIdCert());

    ConsumerResource cr =
        new ConsumerResource(
            mockedConsumerCurator,
            null,
            null,
            ssa,
            null,
            mockedIdSvc,
            null,
            null,
            sink,
            eventFactory,
            null,
            null,
            null,
            null,
            null,
            mockedOwnerCurator,
            null,
            null,
            rules,
            null,
            null,
            null,
            new CandlepinCommonTestConfig(),
            null,
            null,
            null,
            consumerBindUtil,
            productCurator,
            null);
    Consumer c = cr.getConsumer(consumer.getUuid());

    assertFalse(origserial.equals(c.getIdCert().getSerial().getSerial()));
  }
Exemplo n.º 4
0
  @Test
  public void testRegenerateIdCerts() throws GeneralSecurityException, IOException {

    // using lconsumer simply to avoid hiding consumer. This should
    // get renamed once we refactor this test suite.
    IdentityCertServiceAdapter mockedIdSvc = Mockito.mock(IdentityCertServiceAdapter.class);

    EventSink sink = Mockito.mock(EventSinkImpl.class);

    Consumer consumer = createConsumer();
    consumer.setIdCert(createIdCert());
    IdentityCertificate ic = consumer.getIdCert();
    assertNotNull(ic);

    when(mockedConsumerCurator.verifyAndLookupConsumer(consumer.getUuid())).thenReturn(consumer);
    when(mockedIdSvc.regenerateIdentityCert(consumer)).thenReturn(createIdCert());

    ConsumerResource cr =
        new ConsumerResource(
            mockedConsumerCurator,
            null,
            null,
            null,
            null,
            mockedIdSvc,
            null,
            null,
            sink,
            eventFactory,
            null,
            null,
            null,
            null,
            null,
            mockedOwnerCurator,
            null,
            null,
            null,
            null,
            null,
            null,
            new CandlepinCommonTestConfig(),
            null,
            null,
            null,
            consumerBindUtil,
            productCurator,
            null);

    Consumer fooc = cr.regenerateIdentityCertificates(consumer.getUuid());

    assertNotNull(fooc);
    IdentityCertificate ic1 = fooc.getIdCert();
    assertNotNull(ic1);
    assertFalse(ic.equals(ic1));
  }
Exemplo n.º 5
0
  @Test
  public void testGetComplianceStatusList() {
    Consumer c = mock(Consumer.class);
    Consumer c2 = mock(Consumer.class);
    when(c.getUuid()).thenReturn("1");
    when(c2.getUuid()).thenReturn("2");

    List<Consumer> consumers = new ArrayList<Consumer>();
    consumers.add(c);
    consumers.add(c2);

    List<String> uuids = new ArrayList<String>();
    uuids.add("1");
    uuids.add("2");
    when(mockedConsumerCurator.findByUuids(eq(uuids))).thenReturn(consumers);

    ComplianceStatus status = new ComplianceStatus();
    when(mockedComplianceRules.getStatus(any(Consumer.class), any(Date.class))).thenReturn(status);

    ConsumerResource cr =
        new ConsumerResource(
            mockedConsumerCurator,
            null,
            null,
            null,
            null,
            null,
            null,
            i18n,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            mockedComplianceRules,
            null,
            null,
            null,
            new CandlepinCommonTestConfig(),
            null,
            null,
            null,
            consumerBindUtil,
            productCurator,
            null);

    Map<String, ComplianceStatus> results = cr.getComplianceStatusList(uuids);
    assertEquals(2, results.size());
    assertTrue(results.containsKey("1"));
    assertTrue(results.containsKey("2"));
  }
Exemplo n.º 6
0
  @Test
  public void testAsyncExport() {
    CdnCurator mockedCdnCurator = mock(CdnCurator.class);
    ManifestManager manifestManager = mock(ManifestManager.class);
    ConsumerResource cr =
        new ConsumerResource(
            mockedConsumerCurator,
            null,
            null,
            null,
            null,
            null,
            null,
            i18n,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            mockedOwnerCurator,
            null,
            null,
            null,
            null,
            null,
            null,
            new CandlepinCommonTestConfig(),
            null,
            mockedCdnCurator,
            null,
            null,
            productCurator,
            manifestManager);

    List<KeyValueParameter> extParams = new ArrayList<KeyValueParameter>();
    Owner owner = TestUtil.createOwner();
    Consumer consumer =
        TestUtil.createConsumer(new ConsumerType(ConsumerType.ConsumerTypeEnum.CANDLEPIN), owner);
    Cdn cdn = new Cdn("cdn-label", "test", "url");

    when(mockedConsumerCurator.verifyAndLookupConsumer(eq(consumer.getUuid())))
        .thenReturn(consumer);
    when(mockedCdnCurator.lookupByLabel(eq(cdn.getLabel()))).thenReturn(cdn);

    cr.exportDataAsync(null, consumer.getUuid(), cdn.getLabel(), "prefix", cdn.getUrl(), extParams);
    verify(manifestManager)
        .generateManifestAsync(
            eq(consumer.getUuid()),
            eq(cdn.getLabel()),
            eq("prefix"),
            eq(cdn.getUrl()),
            any(Map.class));
  }
Exemplo n.º 7
0
  @Test(expected = BadRequestException.class)
  public void testCreatePersonConsumerWithActivationKey() {
    Consumer c = mock(Consumer.class);
    Owner o = mock(Owner.class);
    ActivationKey ak = mock(ActivationKey.class);
    NoAuthPrincipal nap = mock(NoAuthPrincipal.class);
    ActivationKeyCurator akc = mock(ActivationKeyCurator.class);
    OwnerCurator oc = mock(OwnerCurator.class);
    ConsumerTypeCurator ctc = mock(ConsumerTypeCurator.class);
    ConsumerContentOverrideCurator ccoc = mock(ConsumerContentOverrideCurator.class);

    ConsumerType cType = new ConsumerType(ConsumerTypeEnum.PERSON);
    when(ak.getId()).thenReturn("testKey");
    when(o.getKey()).thenReturn("testOwner");
    when(akc.lookupForOwner(eq("testKey"), eq(o))).thenReturn(ak);
    when(oc.lookupByKey(eq("testOwner"))).thenReturn(o);
    when(c.getType()).thenReturn(cType);
    when(c.getName()).thenReturn("testConsumer");
    when(ctc.lookupByLabel(eq("person"))).thenReturn(cType);

    ConsumerResource cr =
        new ConsumerResource(
            null,
            ctc,
            null,
            null,
            null,
            null,
            null,
            i18n,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            oc,
            akc,
            null,
            null,
            null,
            null,
            null,
            new CandlepinCommonTestConfig(),
            null,
            null,
            null,
            consumerBindUtil,
            productCurator,
            null);
    cr.create(c, nap, null, "testOwner", "testKey", true);
  }
Exemplo n.º 8
0
  @Test
  public void futureHealing() throws Exception {
    Consumer c = mock(Consumer.class);
    Owner o = mock(Owner.class);
    SubscriptionServiceAdapter sa = mock(SubscriptionServiceAdapter.class);
    Entitler e = mock(Entitler.class);
    ConsumerCurator cc = mock(ConsumerCurator.class);
    ConsumerInstalledProduct cip = mock(ConsumerInstalledProduct.class);
    Set<ConsumerInstalledProduct> products = new HashSet<ConsumerInstalledProduct>();
    products.add(cip);

    when(c.getOwner()).thenReturn(o);
    when(cip.getProductId()).thenReturn("product-foo");
    when(sa.hasUnacceptedSubscriptionTerms(eq(o))).thenReturn(false);
    when(cc.verifyAndLookupConsumerWithEntitlements(eq("fakeConsumer"))).thenReturn(c);

    ConsumerResource cr =
        new ConsumerResource(
            cc,
            null,
            null,
            sa,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            e,
            null,
            null,
            null,
            null,
            new CandlepinCommonTestConfig(),
            null,
            null,
            null,
            consumerBindUtil,
            productCurator,
            null);
    String dtStr = "2011-09-26T18:10:50.184081+00:00";
    Date dt = ResourceDateParser.parseDateString(dtStr);
    cr.bind("fakeConsumer", null, null, null, null, null, false, dtStr, null, null, null);
    AutobindData data = AutobindData.create(c).on(dt);
    verify(e).bindByProducts(eq(data));
  }
Exemplo n.º 9
0
 @Test
 public void testFetchAllConsumersForSomeUUIDs() {
   ConsumerResource cr =
       new ConsumerResource(
           mockedConsumerCurator,
           null,
           null,
           null,
           null,
           null,
           null,
           i18n,
           null,
           null,
           null,
           null,
           null,
           null,
           null,
           null,
           null,
           null,
           null,
           null,
           null,
           null,
           new CandlepinCommonTestConfig(),
           null,
           null,
           null,
           null,
           productCurator,
           null);
   Page<List<Consumer>> page = new Page<List<Consumer>>();
   ArrayList<Consumer> consumers = new ArrayList<Consumer>();
   page.setPageData(consumers);
   when(mockedConsumerCurator.searchOwnerConsumers(
           any(Owner.class),
           anyString(),
           (java.util.Collection<ConsumerType>) any(Collection.class),
           any(List.class),
           any(List.class),
           any(List.class),
           any(List.class),
           any(List.class),
           any(List.class),
           any(PageRequest.class)))
       .thenReturn(page);
   List<String> uuids = new ArrayList<String>();
   uuids.add("swiftuuid");
   List<Consumer> result = cr.list(null, null, null, uuids, null, null, null);
   assertEquals(consumers, result);
 }
Exemplo n.º 10
0
  public void testFetchAllConsumersForOwner() {
    ConsumerResource cr =
        new ConsumerResource(
            mockedConsumerCurator,
            null,
            null,
            null,
            null,
            null,
            null,
            i18n,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            mockedOwnerCurator,
            null,
            null,
            null,
            null,
            null,
            null,
            new CandlepinCommonTestConfig(),
            null,
            null,
            null,
            null,
            productCurator,
            null);
    Page<List<Consumer>> page = new Page<List<Consumer>>();
    ArrayList<Consumer> consumers = new ArrayList<Consumer>();
    page.setPageData(consumers);

    when(mockedOwnerCurator.lookupByKey(eq("taylorOwner"))).thenReturn(new Owner());
    when(mockedConsumerCurator.searchOwnerConsumers(
            any(Owner.class),
            anyString(),
            (java.util.Collection<ConsumerType>) any(Collection.class),
            any(List.class),
            any(List.class),
            any(List.class),
            any(List.class),
            any(List.class),
            any(List.class),
            any(PageRequest.class)))
        .thenReturn(page);
    List<Consumer> result = cr.list(null, null, "taylorOwner", null, null, null, null);
    assertEquals(consumers, result);
  }
Exemplo n.º 11
0
  @Test(expected = BadRequestException.class)
  public void testBindMultipleParamsBodyAndProducts() throws Exception {
    ConsumerCurator consumerCurator = mock(ConsumerCurator.class);
    ConsumerResource consumerResource =
        new ConsumerResource(
            consumerCurator,
            null,
            null,
            null,
            null,
            null,
            null,
            i18n,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            new CandlepinCommonTestConfig(),
            null,
            null,
            null,
            consumerBindUtil,
            productCurator,
            null);

    PoolIdAndQuantity[] pools = new PoolIdAndQuantity[2];
    pools[0] = new PoolIdAndQuantity("first", 1);
    pools[1] = new PoolIdAndQuantity("second", 2);

    consumerResource.bind(
        "fake uuid",
        null,
        new String[] {"12232"},
        null,
        null,
        null,
        false,
        null,
        null,
        pools,
        null);
  }
Exemplo n.º 12
0
  @Test(expected = NotFoundException.class)
  public void testNullPerson() {
    Consumer c = mock(Consumer.class);
    Owner o = mock(Owner.class);
    UserServiceAdapter usa = mock(UserServiceAdapter.class);
    UserPrincipal up = mock(UserPrincipal.class);
    OwnerCurator oc = mock(OwnerCurator.class);
    ConsumerTypeCurator ctc = mock(ConsumerTypeCurator.class);
    ConsumerType cType = new ConsumerType(ConsumerTypeEnum.PERSON);

    when(o.getKey()).thenReturn("testOwner");
    when(oc.lookupByKey(eq("testOwner"))).thenReturn(o);
    when(c.getType()).thenReturn(cType);
    when(c.getName()).thenReturn("testConsumer");
    when(ctc.lookupByLabel(eq("person"))).thenReturn(cType);
    when(up.canAccess(eq(o), eq(SubResource.CONSUMERS), eq(Access.CREATE))).thenReturn(true);
    // usa.findByLogin() will return null by default no need for a when

    ConsumerResource cr =
        new ConsumerResource(
            null,
            ctc,
            null,
            null,
            null,
            null,
            null,
            i18n,
            null,
            null,
            null,
            null,
            usa,
            null,
            null,
            oc,
            null,
            null,
            null,
            null,
            null,
            null,
            new CandlepinCommonTestConfig(),
            null,
            null,
            null,
            consumerBindUtil,
            productCurator,
            null);
    cr.create(c, up, null, "testOwner", null, true);
  }
Exemplo n.º 13
0
  @Test
  public void testProductNoPool() throws Exception {
    Consumer c = mock(Consumer.class);
    Owner o = mock(Owner.class);
    SubscriptionServiceAdapter sa = mock(SubscriptionServiceAdapter.class);
    Entitler e = mock(Entitler.class);
    ConsumerCurator cc = mock(ConsumerCurator.class);
    String[] prodIds = {"notthere"};

    when(c.getOwner()).thenReturn(o);
    when(sa.hasUnacceptedSubscriptionTerms(eq(o))).thenReturn(false);
    when(cc.verifyAndLookupConsumerWithEntitlements(eq("fakeConsumer"))).thenReturn(c);
    when(e.bindByProducts(any(AutobindData.class))).thenReturn(null);

    ConsumerResource cr =
        new ConsumerResource(
            cc,
            null,
            null,
            sa,
            null,
            null,
            null,
            i18n,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            e,
            null,
            null,
            null,
            null,
            new CandlepinCommonTestConfig(),
            null,
            null,
            null,
            consumerBindUtil,
            productCurator,
            null);
    Response r =
        cr.bind("fakeConsumer", null, prodIds, null, null, null, false, null, null, null, null);
    assertEquals(null, r.getEntity());
  }
Exemplo n.º 14
0
  @Test
  public void testIdCertDoesNotRegenerate() throws Exception {
    SubscriptionServiceAdapter ssa = Mockito.mock(SubscriptionServiceAdapter.class);
    ComplianceRules rules = Mockito.mock(ComplianceRules.class);

    Consumer consumer = createConsumer();
    ComplianceStatus status = new ComplianceStatus();
    when(rules.getStatus(any(Consumer.class), any(Date.class), anyBoolean())).thenReturn(status);
    consumer.setIdCert(createIdCert(TestUtil.createDate(2025, 6, 9)));
    BigInteger origserial = consumer.getIdCert().getSerial().getSerial();

    when(mockedConsumerCurator.verifyAndLookupConsumer(consumer.getUuid())).thenReturn(consumer);

    ConsumerResource cr =
        new ConsumerResource(
            mockedConsumerCurator,
            null,
            null,
            ssa,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            mockedOwnerCurator,
            null,
            null,
            rules,
            null,
            null,
            null,
            new CandlepinCommonTestConfig(),
            null,
            null,
            null,
            consumerBindUtil,
            productCurator,
            null);

    Consumer c = cr.getConsumer(consumer.getUuid());

    assertEquals(origserial, c.getIdCert().getSerial().getSerial());
  }
Exemplo n.º 15
0
  @Test(expected = BadRequestException.class)
  public void testBindMultipleParams() throws Exception {
    ConsumerCurator consumerCurator = mock(ConsumerCurator.class);
    ConsumerResource consumerResource =
        new ConsumerResource(
            consumerCurator,
            null,
            null,
            null,
            null,
            null,
            null,
            i18n,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            new CandlepinCommonTestConfig(),
            null,
            null,
            null,
            consumerBindUtil,
            productCurator,
            null);

    consumerResource.bind(
        "fake uuid",
        "fake pool uuid",
        new String[] {"12232"},
        1,
        null,
        null,
        false,
        null,
        null,
        null,
        null);
  }
Exemplo n.º 16
0
  @Test
  public void testGetCertSerials() {
    Consumer consumer = createConsumer();
    List<EntitlementCertificate> certificates = createEntitlementCertificates();

    when(mockedEntitlementCertServiceAdapter.listForConsumer(consumer)).thenReturn(certificates);
    when(mockedConsumerCurator.verifyAndLookupConsumer(consumer.getUuid())).thenReturn(consumer);
    when(mockedEntitlementCurator.listByConsumer(consumer))
        .thenReturn(new ArrayList<Entitlement>());

    ConsumerResource consumerResource =
        new ConsumerResource(
            mockedConsumerCurator,
            null,
            null,
            null,
            mockedEntitlementCurator,
            null,
            mockedEntitlementCertServiceAdapter,
            null,
            null,
            null,
            null,
            null,
            null,
            mockedPoolManager,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            new CandlepinCommonTestConfig(),
            null,
            null,
            null,
            consumerBindUtil,
            productCurator,
            null);

    List<CertificateSerialDto> serials =
        consumerResource.getEntitlementCertificateSerials(consumer.getUuid());

    verifyCertificateSerialNumbers(serials);
  }
Exemplo n.º 17
0
  @Test
  public void testNoDryBindWhenAutobindDisabledForOwner() throws Exception {
    Consumer consumer = createConsumer();
    consumer.getOwner().setAutobindDisabled(true);
    when(mockedConsumerCurator.verifyAndLookupConsumer(eq(consumer.getUuid())))
        .thenReturn(consumer);
    ManifestManager manifestManager = mock(ManifestManager.class);
    ConsumerResource consumerResource =
        new ConsumerResource(
            mockedConsumerCurator,
            null,
            null,
            null,
            null,
            null,
            null,
            i18n,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            mockedOwnerCurator,
            null,
            null,
            null,
            null,
            null,
            null,
            new CandlepinCommonTestConfig(),
            null,
            null,
            null,
            null,
            productCurator,
            manifestManager);

    try {
      consumerResource.dryBind(consumer.getUuid(), "some-sla");
      fail("Should have thrown a BadRequestException.");
    } catch (BadRequestException e) {
      assertEquals("Owner has autobind disabled.", e.getMessage());
    }
  }
Exemplo n.º 18
0
  /** Basic test. If invalid id is given, should throw {@link NotFoundException} */
  @Test(expected = NotFoundException.class)
  public void unbindByInvalidPoolIdShouldFail() {
    Consumer consumer = createConsumer();
    ConsumerCurator consumerCurator = mock(ConsumerCurator.class);
    when(consumerCurator.verifyAndLookupConsumer(eq("fake-uuid"))).thenReturn(consumer);
    EntitlementCurator entitlementCurator = mock(EntitlementCurator.class);

    when(entitlementCurator.listByConsumerAndPoolId(eq(consumer), any(String.class)))
        .thenReturn(new ArrayList<Entitlement>());

    ConsumerResource consumerResource =
        new ConsumerResource(
            consumerCurator,
            null,
            null,
            null,
            entitlementCurator,
            null,
            null,
            i18n,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            new CandlepinCommonTestConfig(),
            null,
            null,
            null,
            consumerBindUtil,
            productCurator,
            null);
    consumerResource.unbindByPool("fake-uuid", "Run Forest!");
  }
Exemplo n.º 19
0
  @Test(expected = NotFoundException.class)
  public void unbindByInvalidSerialShouldFail() {
    Consumer consumer = createConsumer();
    ConsumerCurator consumerCurator = mock(ConsumerCurator.class);
    when(consumerCurator.verifyAndLookupConsumer(eq("fake uuid"))).thenReturn(consumer);

    EntitlementCurator entitlementCurator = mock(EntitlementCurator.class);
    when(entitlementCurator.find(any(Serializable.class))).thenReturn(null);

    ConsumerResource consumerResource =
        new ConsumerResource(
            consumerCurator,
            null,
            null,
            null,
            entitlementCurator,
            null,
            null,
            i18n,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            new CandlepinCommonTestConfig(),
            null,
            null,
            null,
            consumerBindUtil,
            productCurator,
            null);

    consumerResource.unbindBySerial("fake uuid", Long.valueOf(1234L));
  }
Exemplo n.º 20
0
  /**
   * Test just verifies that entitler is called only once and it doesn't need any other object to
   * execute.
   */
  @Test
  public void testRegenerateEntitlementCertificateWithValidConsumer() {
    Consumer consumer = createConsumer();

    when(mockedConsumerCurator.verifyAndLookupConsumer(consumer.getUuid())).thenReturn(consumer);

    CandlepinPoolManager mgr = mock(CandlepinPoolManager.class);
    ConsumerResource cr =
        new ConsumerResource(
            mockedConsumerCurator,
            null,
            null,
            mockedSubscriptionServiceAdapter,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            mgr,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            new CandlepinCommonTestConfig(),
            null,
            null,
            null,
            consumerBindUtil,
            productCurator,
            null);
    cr.regenerateEntitlementCertificates(consumer.getUuid(), null, true);
    Mockito.verify(mgr, Mockito.times(1)).regenerateCertificatesOf(eq(consumer), eq(true));
  }
Exemplo n.º 21
0
  @Test(expected = NotFoundException.class)
  public void testBindByPoolBadConsumerUuid() throws Exception {
    ConsumerCurator consumerCurator = mock(ConsumerCurator.class);
    when(consumerCurator.verifyAndLookupConsumerWithEntitlements(any(String.class)))
        .thenThrow(new NotFoundException(""));
    ConsumerResource consumerResource =
        new ConsumerResource(
            consumerCurator,
            null,
            null,
            null,
            null,
            null,
            null,
            i18n,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            new CandlepinCommonTestConfig(),
            null,
            null,
            null,
            consumerBindUtil,
            productCurator,
            null);

    consumerResource.bind(
        "notarealuuid", "fake pool uuid", null, null, null, null, false, null, null, null, null);
  }
Exemplo n.º 22
0
  /** Basic test. If invalid id is given, should throw {@link NotFoundException} */
  @Test(expected = NotFoundException.class)
  public void testRegenerateEntitlementCertificatesWithInvalidConsumerId() {
    ConsumerCurator consumerCurator = mock(ConsumerCurator.class);
    when(consumerCurator.verifyAndLookupConsumer(any(String.class)))
        .thenThrow(new NotFoundException(""));
    ConsumerResource consumerResource =
        new ConsumerResource(
            consumerCurator,
            null,
            null,
            null,
            null,
            null,
            null,
            i18n,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            new CandlepinCommonTestConfig(),
            null,
            null,
            null,
            consumerBindUtil,
            productCurator,
            null);

    consumerResource.regenerateEntitlementCertificates("xyz", null, true);
  }
Exemplo n.º 23
0
 @Test
 public void testConsumerExistsYes() {
   when(mockedConsumerCurator.doesConsumerExist(any(String.class))).thenReturn(true);
   ConsumerResource cr =
       new ConsumerResource(
           mockedConsumerCurator,
           null,
           null,
           null,
           null,
           null,
           null,
           i18n,
           null,
           null,
           null,
           null,
           null,
           null,
           null,
           null,
           null,
           null,
           mockedComplianceRules,
           null,
           null,
           null,
           new CandlepinCommonTestConfig(),
           null,
           null,
           null,
           consumerBindUtil,
           productCurator,
           null);
   cr.consumerExists("uuid");
 }
Exemplo n.º 24
0
 @Test(expected = NotFoundException.class)
 public void testConsumerExistsNo() {
   when(mockedConsumerCurator.doesConsumerExist(any(String.class))).thenReturn(false);
   ConsumerResource cr =
       new ConsumerResource(
           mockedConsumerCurator,
           null,
           null,
           null,
           null,
           null,
           null,
           i18n,
           null,
           null,
           null,
           null,
           null,
           null,
           null,
           null,
           null,
           null,
           mockedComplianceRules,
           null,
           null,
           null,
           new CandlepinCommonTestConfig(),
           null,
           null,
           null,
           consumerBindUtil,
           productCurator,
           null);
   cr.consumerExists("uuid");
 }
Exemplo n.º 25
0
  @SuppressWarnings("unchecked")
  @Test
  public void testBindByPools() throws Exception {
    PoolIdAndQuantity[] pools = new PoolIdAndQuantity[2];
    pools[0] = new PoolIdAndQuantity("first", 1);
    pools[1] = new PoolIdAndQuantity("second", 2);
    ConsumerCurator cc = mock(ConsumerCurator.class);
    SubscriptionServiceAdapter sa = mock(SubscriptionServiceAdapter.class);
    PoolManager pm = mock(PoolManager.class);
    Owner owner = TestUtil.createOwner();
    Consumer consumer = TestUtil.createConsumer(owner);

    when(cc.verifyAndLookupConsumerWithEntitlements(eq("fakeConsumer"))).thenReturn(consumer);
    when(sa.hasUnacceptedSubscriptionTerms(any(Owner.class))).thenReturn(false);

    ConsumerResource cr =
        new ConsumerResource(
            cc,
            null,
            null,
            sa,
            null,
            null,
            null,
            i18n,
            null,
            null,
            null,
            null,
            null,
            pm,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            new CandlepinCommonTestConfig(),
            null,
            null,
            null,
            consumerBindUtil,
            productCurator,
            null);

    Response rsp =
        cr.bind(
            "fakeConsumer",
            null,
            null,
            null,
            null,
            null,
            true,
            null,
            null,
            pools,
            new TrustedUserPrincipal("TaylorSwift"));

    JobDetail detail = (JobDetail) rsp.getEntity();
    PoolIdAndQuantity[] pQs =
        (PoolIdAndQuantity[]) detail.getJobDataMap().get("pool_and_quantities");
    boolean firstFound = false;
    boolean secondFound = false;
    for (PoolIdAndQuantity pq : pQs) {
      if (pq.getPoolId().contentEquals("first")) {
        firstFound = true;
        assertEquals(1, pq.getQuantity().intValue());
      }
      if (pq.getPoolId().contentEquals("second")) {
        secondFound = true;
        assertEquals(2, pq.getQuantity().intValue());
      }
    }
    assertTrue(firstFound);
    assertTrue(secondFound);
  }
Exemplo n.º 26
0
  @Test(expected = RuntimeException.class)
  public void testExceptionFromCertGen() throws Exception {
    Consumer consumer = createConsumer();

    Entitlement e = Mockito.mock(Entitlement.class);
    Pool p = Mockito.mock(Pool.class);
    Subscription s = Mockito.mock(Subscription.class);
    when(e.getPool()).thenReturn(p);
    when(p.getSubscriptionId()).thenReturn("4444");

    when(mockedConsumerCurator.verifyAndLookupConsumer(consumer.getUuid())).thenReturn(consumer);
    when(mockedEntitlementCurator.find(eq("9999"))).thenReturn(e);
    when(mockedSubscriptionServiceAdapter.getSubscription(eq("4444"))).thenReturn(s);

    when(mockedEntitlementCertServiceAdapter.generateEntitlementCert(
            any(Entitlement.class), any(Product.class)))
        .thenThrow(new IOException());

    CandlepinPoolManager poolManager =
        new CandlepinPoolManager(
            null,
            null,
            null,
            new CandlepinCommonTestConfig(),
            null,
            null,
            mockedEntitlementCurator,
            mockedConsumerCurator,
            null,
            null,
            null,
            null,
            mockedActivationKeyRules,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null);

    ConsumerResource consumerResource =
        new ConsumerResource(
            mockedConsumerCurator,
            null,
            null,
            null,
            mockedEntitlementCurator,
            null,
            mockedEntitlementCertServiceAdapter,
            null,
            null,
            null,
            null,
            null,
            null,
            poolManager,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            new CandlepinCommonTestConfig(),
            null,
            null,
            null,
            consumerBindUtil,
            productCurator,
            null);

    consumerResource.regenerateEntitlementCertificates(consumer.getUuid(), "9999", false);
  }
Exemplo n.º 27
0
  @Test
  public void testcheckForGuestsMigration() {
    ConsumerResource cr =
        Mockito.spy(
            new ConsumerResource(
                mockedConsumerCurator,
                null,
                null,
                null,
                null,
                null,
                null,
                i18n,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                new CandlepinCommonTestConfig(),
                null,
                null,
                null,
                null,
                productCurator,
                null));
    List<GuestId> startGuests = new ArrayList<GuestId>();
    List<GuestId> updatedGuests = new ArrayList<GuestId>();
    VirtConsumerMap guestConsumerMap = new VirtConsumerMap();
    Owner o = mock(Owner.class);
    Consumer host = new Consumer();

    Consumer cOne = new Consumer();
    cOne.setFact("virt.is_guest", "true");
    cOne.setFact("virt.uuid", cOne.getUuid() + "-vuuid");
    cOne.setOwner(o);
    GuestId one = new GuestId(cOne.getFact("virt.uuid"));
    startGuests.add(one);
    guestConsumerMap.add(cOne.getFact("virt.uuid"), cOne);

    Consumer cTwo = new Consumer();
    cTwo.setFact("virt.is_guest", "true");
    cTwo.setFact("virt.uuid", cTwo.getUuid() + "-vuuid");
    cTwo.setOwner(o);
    GuestId two = new GuestId(cTwo.getFact("virt.uuid"));
    startGuests.add(two);
    updatedGuests.add(two);
    guestConsumerMap.add(cTwo.getFact("virt.uuid"), cTwo);

    Consumer cThree = new Consumer();
    cThree.setFact("virt.is_guest", "true");
    cThree.setFact("virt.uuid", cThree.getUuid() + "-vuuid");
    cThree.setOwner(o);
    GuestId three = new GuestId(cThree.getFact("virt.uuid"));
    updatedGuests.add(three);
    guestConsumerMap.add(cThree.getFact("virt.uuid"), cThree);

    cr.checkForGuestsMigration(host, startGuests, updatedGuests, guestConsumerMap);
    verify(cr).checkForGuestMigration(host, cOne);
    verify(cr).checkForGuestMigration(host, cTwo);
    verify(cr).checkForGuestMigration(host, cThree);
  }