コード例 #1
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);
  }
コード例 #2
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);
  }