Search in sources :

Example 86 with Owner

use of org.candlepin.model.Owner in project candlepin by candlepin.

the class RefresherTest method testPoolOnlyExaminedOnceProductAndOwner.

@Test
public void testPoolOnlyExaminedOnceProductAndOwner() {
    Owner owner = TestUtil.createOwner();
    Product product = mock(Product.class);
    ProductData productData = mock(ProductData.class);
    when(product.getUuid()).thenReturn("product id");
    when(product.toDTO()).thenReturn(productData);
    Pool pool = new Pool();
    pool.setSourceSubscription(new SourceSubscription("subId", "master"));
    pool.setOwner(owner);
    Subscription subscription = new Subscription();
    subscription.setId("subId");
    subscription.setOwner(owner);
    List<Pool> pools = new ArrayList<>();
    pools.add(pool);
    List<Subscription> subscriptions = new ArrayList<>();
    subscriptions.add(subscription);
    when(subAdapter.getSubscriptions(eq(productData))).thenReturn(subscriptions);
    when(subAdapter.getSubscriptions(owner)).thenReturn(subscriptions);
    when(subAdapter.getSubscription("subId")).thenReturn(subscription);
    when(poolManager.lookupBySubscriptionId(owner, "subId")).thenReturn(pools);
    refresher.add(owner);
    refresher.add(product);
    refresher.run();
    verify(poolManager, times(1)).refreshPoolsWithRegeneration(eq(subAdapter), eq(owner), eq(false));
    verify(poolManager, times(0)).updatePoolsForMasterPool(any(List.class), any(Pool.class), eq(pool.getQuantity()), eq(false), any(Map.class));
}
Also used : ProductData(org.candlepin.model.dto.ProductData) Owner(org.candlepin.model.Owner) SourceSubscription(org.candlepin.model.SourceSubscription) ArrayList(java.util.ArrayList) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) ArrayList(java.util.ArrayList) List(java.util.List) Subscription(org.candlepin.model.dto.Subscription) SourceSubscription(org.candlepin.model.SourceSubscription) Map(java.util.Map) Test(org.junit.Test)

Example 87 with Owner

use of org.candlepin.model.Owner in project candlepin by candlepin.

the class EventSinkImplTest method importCreatedShouldEmitSuccessfully.

@Test
public void importCreatedShouldEmitSuccessfully() throws Exception {
    Owner owner = new Owner("Import guy");
    eventSinkImpl.emitImportCreated(owner);
    eventSinkImpl.sendEvents();
    verify(mockClientProducer).send(any(ClientMessage.class));
}
Also used : Owner(org.candlepin.model.Owner) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Test(org.junit.Test)

Example 88 with Owner

use of org.candlepin.model.Owner in project candlepin by candlepin.

the class EventSinkImplTest method emptyKeyShouldEmitSuccessfully.

@Test
public void emptyKeyShouldEmitSuccessfully() throws Exception {
    ActivationKey key = TestUtil.createActivationKey(new Owner("deadbeef"), null);
    eventSinkImpl.emitActivationKeyCreated(key);
    eventSinkImpl.sendEvents();
    verify(mockClientProducer).send(any(ClientMessage.class));
}
Also used : Owner(org.candlepin.model.Owner) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) Test(org.junit.Test)

Example 89 with Owner

use of org.candlepin.model.Owner in project candlepin by candlepin.

the class BasicAuthViaUserServiceTest method correctPrincipalNoPassword.

@Test
public void correctPrincipalNoPassword() throws Exception {
    Owner owner = new Owner("user", "user");
    setUserNoPassword("user");
    when(userService.validateUser("user", null)).thenReturn(true);
    Set<OwnerPermission> permissions = new HashSet<>();
    permissions.add(new OwnerPermission(owner, Access.ALL));
    when(userService.findByLogin("user")).thenReturn(new User());
    UserPrincipal expected = new UserPrincipal("user", new ArrayList<>(permissions), false);
    assertEquals(expected, this.auth.getPrincipal(request));
}
Also used : Owner(org.candlepin.model.Owner) OwnerPermission(org.candlepin.auth.permissions.OwnerPermission) User(org.candlepin.model.User) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 90 with Owner

use of org.candlepin.model.Owner in project candlepin by candlepin.

the class BasicAuthViaUserServiceTest method correctPrincipal.

/**
 * Valid credentials are given - checks if the correct principal is created.
 *
 * @throws Exception
 */
@Test
public void correctPrincipal() throws Exception {
    Owner owner = new Owner("user", "user");
    setUserAndPassword("user", "redhat");
    when(userService.validateUser("user", "redhat")).thenReturn(true);
    // TODO: test will fail, need to mock the permissions setup
    Set<OwnerPermission> permissions = new HashSet<>();
    permissions.add(new OwnerPermission(owner, Access.ALL));
    when(userService.findByLogin("user")).thenReturn(new User());
    UserPrincipal expected = new UserPrincipal("user", new ArrayList<>(permissions), false);
    assertEquals(expected, this.auth.getPrincipal(request));
}
Also used : Owner(org.candlepin.model.Owner) OwnerPermission(org.candlepin.auth.permissions.OwnerPermission) User(org.candlepin.model.User) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Owner (org.candlepin.model.Owner)405 Test (org.junit.Test)254 Product (org.candlepin.model.Product)153 Consumer (org.candlepin.model.Consumer)127 Pool (org.candlepin.model.Pool)79 Date (java.util.Date)72 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)71 ArrayList (java.util.ArrayList)58 Produces (javax.ws.rs.Produces)52 ConsumerType (org.candlepin.model.ConsumerType)52 ApiOperation (io.swagger.annotations.ApiOperation)50 HashSet (java.util.HashSet)44 Entitlement (org.candlepin.model.Entitlement)44 Path (javax.ws.rs.Path)42 HashMap (java.util.HashMap)41 ApiResponses (io.swagger.annotations.ApiResponses)40 Content (org.candlepin.model.Content)39 BadRequestException (org.candlepin.common.exceptions.BadRequestException)37 Subscription (org.candlepin.model.dto.Subscription)32 List (java.util.List)29