Search in sources :

Example 56 with SyndFeed

use of com.sun.syndication.feed.synd.SyndFeed in project rhsm-qe by RedHatQE.

the class EventTests method testConsumerModified.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-21845", "RHEL7-51666" }, level = DefTypes.Level.COMPONENT, component = "subscription-manager", testtype = @TestType(testtype = DefTypes.TestTypes.FUNCTIONAL, subtype1 = DefTypes.Subtypes.RELIABILITY, subtype2 = DefTypes.Subtypes.EMPTY), posneg = PosNeg.POSITIVE, importance = DefTypes.Importance.HIGH, automation = DefTypes.Automation.AUTOMATED, tags = "Tier3")
@Test(description = "subscription-manager: events: Consumer Modified is sent over an RSS atom feed.", groups = { "Tier3Tests", "blockedByBug-721141", "ConsumerModified_Test" }, dependsOnGroups = { "EnititlementDeleted_Test" }, enabled = true)
public // @ImplementsTCMS(id="")
void testConsumerModified() throws Exception {
    // get the owner and consumer feeds before we test the firing of a new event
    ConsumerCert consumerCert = clienttasks.getCurrentConsumerCert();
    String ownerKey = CandlepinTasks.getOwnerKeyOfConsumerId(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, consumerCert.consumerid);
    SyndFeed oldFeed = CandlepinTasks.getSyndFeed(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl);
    SyndFeed oldOwnerFeed = CandlepinTasks.getSyndFeedForOwner(ownerKey, sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl);
    SyndFeed oldConsumerFeed = CandlepinTasks.getSyndFeedForConsumer(/*ownerKey,*/
    consumerCert.consumerid, sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl);
    // fire an facts update event by overriding a fact in /etc/rhsm/facts/event_tests.facts
    Map<String, String> eventFacts = new HashMap<String, String>();
    eventFacts.put("events.test.description", "Testing CONSUMER MODIFIED event fires on facts update.");
    eventFacts.put("events.test.currentTimeMillis", String.valueOf(System.currentTimeMillis()));
    clienttasks.createFactsFileWithOverridingValues(eventFacts);
    clienttasks.facts(null, true, null, null, null, null);
    // FYI: Another way to fire a consumer modified event is to call CandlepinTasks.setAutohealForConsumer(authenticator, password, url, consumerid, autoheal);
    String[] newEventTitles = new String[] { "CONSUMER MODIFIED" };
    // COMPLIANCE CREATED events were added to support gutterball
    newEventTitles = new String[] { "COMPLIANCE CREATED", "CONSUMER MODIFIED" };
    if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "2.1.1-1")) {
        // commit 1ad3fd6f338d9bbcedc8eba8361d4bc6c807f84d	1474443 compliance.created events now use UUID for 'consumerId' field
        newEventTitles = new String[] { "CONSUMER MODIFIED" };
    }
    // assert the consumer feed...
    // assertTheNewConsumerFeed(ownerKey, consumerCert.consumerid, oldConsumerFeed, newEventTitles);
    assertTheNewConsumerFeedIgnoringEventTitles(ownerKey, consumerCert.consumerid, oldConsumerFeed, newEventTitles, new HashSet<String>() {

        {
            add("COMPLIANCE CREATED");
        }
    });
    // assert the owner feed...
    // assertTheNewOwnerFeed(ownerKey, oldOwnerFeed, newEventTitles);
    assertTheNewOwnerFeedIgnoringEventTitles(ownerKey, oldOwnerFeed, newEventTitles, new HashSet<String>() {

        {
            add("COMPLIANCE CREATED");
        }
    });
    // assert the feed...
    // assertTheNewFeed(oldFeed, newEventTitles);
    assertTheNewFeedIgnoringEventTitles(oldFeed, newEventTitles, new HashSet<String>() {

        {
            add("COMPLIANCE CREATED");
        }
    });
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed) HashMap(java.util.HashMap) ConsumerCert(rhsm.data.ConsumerCert) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 57 with SyndFeed

use of com.sun.syndication.feed.synd.SyndFeed in project rhsm-qe by RedHatQE.

the class EventTests method testPoolModifiedAndEntitlementModified.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-26757", "RHEL7-52091" }, level = DefTypes.Level.COMPONENT, component = "subscription-manager", testtype = @TestType(testtype = DefTypes.TestTypes.FUNCTIONAL, subtype1 = DefTypes.Subtypes.RELIABILITY, subtype2 = DefTypes.Subtypes.EMPTY), posneg = PosNeg.POSITIVE, importance = DefTypes.Importance.HIGH, automation = DefTypes.Automation.AUTOMATED, tags = "Tier3")
@Test(description = "subscription-manager: events: Pool Modified and Entitlement Modified is sent over an RSS atom feed.", groups = { "Tier3Tests", "blockedByBug-721141", "PoolModifiedAndEntitlementModified_Test", "blockedByBug-645597", "blockedByBug-1303242", "blockedByBug-1500837", "blockedByBug-1500843" }, dependsOnGroups = { "EntitlementCreated_Test" }, enabled = true)
public // @ImplementsTCMS(id="")
void testPoolModifiedAndEntitlementModified() throws Exception {
    if (server == null)
        throw new SkipException("This test requires an SSH connection to the candlepin server.");
    // get the owner and consumer feeds before we test the firing of a new event
    ConsumerCert consumerCert = clienttasks.getCurrentConsumerCert();
    String ownerKey = CandlepinTasks.getOwnerKeyOfConsumerId(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, consumerCert.consumerid);
    // get the number of subscriptions this owner owns
    // JSONArray jsonSubscriptions = new JSONArray(CandlepinTasks.getResourceUsingRESTfulAPI(serverHostname,serverPort,serverPrefix,clientusername,clientpassword,"/owners/"+ownerKey+"/subscriptions"));
    // find the first pool id of a currently consumed product
    List<ProductSubscription> consumedProductSubscriptions = clienttasks.getCurrentlyConsumedProductSubscriptions();
    ProductSubscription originalConsumedProductSubscription = consumedProductSubscriptions.get(0);
    testPool = clienttasks.getSubscriptionPoolFromProductSubscription(originalConsumedProductSubscription, sm_clientUsername, sm_clientPassword);
    Calendar originalStartDate = (Calendar) originalConsumedProductSubscription.startDate.clone();
    EntitlementCert originalEntitlementCert = clienttasks.getEntitlementCertCorrespondingToProductSubscription(originalConsumedProductSubscription);
    originalStartDate = (Calendar) originalEntitlementCert.validityNotBefore.clone();
    SyndFeed oldFeed = CandlepinTasks.getSyndFeed(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl);
    SyndFeed oldOwnerFeed = CandlepinTasks.getSyndFeedForOwner(ownerKey, sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl);
    SyndFeed oldConsumerFeed = CandlepinTasks.getSyndFeedForConsumer(/*ownerKey,*/
    consumerCert.consumerid, sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl);
    // fire an modified pool event (and subsequently a modified entitlement event because the pool was modified thereby requiring an entitlement update dropped to the consumer)
    log.info("To fire a modified pool event (and subsequently a modified entitlement event because the pool is already subscribed too), we will modify pool '" + testPool.poolId + "' by subtracting one month from startdate...");
    Calendar newStartDate = (Calendar) originalStartDate.clone();
    newStartDate.add(Calendar.MONTH, -1);
    if (false) {
        // the following block was used prior to candlepin-2.0.0 and replaced by CandlepinTasks.updateSubscriptionAndRefreshPoolsUsingRESTfulAPI which I think will also work for pre candlepin-2.0.0, but is untested.  <== TODO
        updateSubscriptionPoolDatesOnDatabase(testPool, newStartDate, null);
        log.info("Now let's refresh the subscription pools to expose the POOL MODIFIED event...");
        JSONObject jobDetail = CandlepinTasks.refreshPoolsUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, ownerKey);
        jobDetail = CandlepinTasks.waitForJobDetailStateUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, jobDetail, "FINISHED", 10 * 1000, 3);
    } else
        /*OLD*/
        CandlepinTasks.updateSubscriptionDatesAndRefreshPoolsUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, CandlepinTasks.getSubscriptionIdForPoolId(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, testPool.poolId), newStartDate, null);
    // NEW TODO CandlepinTasks.updateSubscriptionPoolDatesUsingRESTfulAPI(sm_serverAdminUsername,sm_serverAdminPassword,sm_serverUrl, testPool.poolId,newStartDate,null);
    // assert the consumer feed...
    List<String> newEventTitles = new ArrayList<String>();
    // newEventTitles.add("ENTITLEMENT MODIFIED");
    assertTheNewConsumerFeed(ownerKey, consumerCert.consumerid, oldConsumerFeed, newEventTitles);
    // assert the owner feed...
    // //assertTheNewOwnerFeed(ownerKey, oldOwnerFeed, new String[]{"ENTITLEMENT MODIFIED", "POOL MODIFIED"});
    // for (int s=0; s<jsonSubscriptions.length(); s++) newEventTitles.add("POOL MODIFIED");		// NOTE: This is troublesome because the number of POOL MODIFIED events is not this predictable especially when the pool (which is randomly chosen) is a virt pool
    // assertTheNewOwnerFeed(ownerKey, oldOwnerFeed, newEventTitles);
    newEventTitles.add("POOL MODIFIED");
    assertTheNewOwnerFeedContains(ownerKey, oldOwnerFeed, newEventTitles);
    // assert the feed...
    // //assertTheNewFeed(oldFeed, new String[]{"ENTITLEMENT MODIFIED", "POOL MODIFIED"});
    // assertTheNewFeed(oldFeed, newEventTitles);
    assertTheNewFeedContains(oldFeed, newEventTitles);
    log.info("Now let's refresh the client's entitlements to expose the ENTITLEMENT MODIFIED event...");
    clienttasks.refresh(null, null, null, null);
    // COMPLIANCE CREATED events were added to support gutterball
    newEventTitles.add("COMPLIANCE CREATED");
    newEventTitles.add("ENTITLEMENT MODIFIED");
    // assert the feed...
    assertTheNewFeedContains(oldFeed, newEventTitles);
    // assert the owner feed...
    assertTheNewOwnerFeedContains(ownerKey, oldOwnerFeed, newEventTitles);
    // assert the consumer feed...
    newEventTitles.remove("POOL MODIFIED");
    // assertTheNewConsumerFeed(ownerKey, consumerCert.consumerid, oldConsumerFeed, newEventTitles);
    assertTheNewConsumerFeedIgnoringEventTitles(ownerKey, consumerCert.consumerid, oldConsumerFeed, newEventTitles.toArray(new String[] {}), new HashSet<String>() {

        {
            add("COMPLIANCE CREATED");
        }
    });
    // TEMPORARY WORKAROUND FOR BUG
    boolean invokeWorkaroundWhileBugIsOpen = true;
    Calendar now = Calendar.getInstance();
    try {
        String bugId = "883486";
        if (invokeWorkaroundWhileBugIsOpen && BzChecker.getInstance().isBugOpen(bugId)) {
            log.fine("Invoking workaround for " + BzChecker.getInstance().getBugState(bugId).toString() + " Bugzilla " + bugId + ".  (https://bugzilla.redhat.com/show_bug.cgi?id=" + bugId + ")");
            SubscriptionManagerCLITestScript.addInvokedWorkaround(bugId);
        } else {
            invokeWorkaroundWhileBugIsOpen = false;
        }
    } catch (BugzillaAPIException be) {
    /* ignore exception */
    } catch (RuntimeException re) {
    /* ignore exception */
    }
    if (invokeWorkaroundWhileBugIsOpen) {
        log.warning("The workaround while this bug is open is to compensate the expected consumed product subscription start date for daylight savings.");
        // adjust the expected entitlement dates for daylight savings time (changed by https://github.com/candlepin/subscription-manager/pull/385)
        // now.get(Calendar.DST_OFFSET) will equal 0 in the winter StandardTime; will equal 1000*60*60 in the summer DaylightSavingsTime (when the local time zone observes DST)
        newStartDate.add(Calendar.MILLISECOND, now.get(Calendar.DST_OFFSET) - newStartDate.get(Calendar.DST_OFFSET));
        newStartDate.add(Calendar.MILLISECOND, now.get(Calendar.DST_OFFSET) - newStartDate.get(Calendar.DST_OFFSET));
    }
    // END OF WORKAROUND
    // ProductSubscription newConsumedProductSubscription = ProductSubscription.findFirstInstanceWithMatchingFieldFromList("serialNumber", originalConsumedProductSubscription.serialNumber, clienttasks.getCurrentlyConsumedProductSubscriptions());	// can't do this because the serialNumber changes after the pool and entitlement have been modified
    ProductSubscription newConsumedProductSubscription = ProductSubscription.findFirstInstanceWithMatchingFieldFromList("productId", originalConsumedProductSubscription.productId, clienttasks.getCurrentlyConsumedProductSubscriptions());
    // AN org.xmlpull.v1.XmlPullParserException IS THROWN WHEN THIS FAILS: Assert.assertEquals(newConsumedProductSubscription.startDate, newStartDate, "After modifying pool '"+testPool.poolId+"' by subtracting one month from startdate and refreshing entitlements, the consumed product subscription now reflects the modified field.");
    Assert.assertEquals(ProductSubscription.formatDateString(newConsumedProductSubscription.startDate), ProductSubscription.formatDateString(newStartDate), "After modifying pool '" + testPool.poolId + "' by subtracting one month from startdate and refreshing entitlements, the consumed product subscription now reflects the modified field.");
}
Also used : EntitlementCert(rhsm.data.EntitlementCert) Calendar(java.util.Calendar) ProductSubscription(rhsm.data.ProductSubscription) ArrayList(java.util.ArrayList) BugzillaAPIException(com.redhat.qe.auto.bugzilla.BugzillaAPIException) SyndFeed(com.sun.syndication.feed.synd.SyndFeed) JSONObject(org.json.JSONObject) SkipException(org.testng.SkipException) ConsumerCert(rhsm.data.ConsumerCert) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 58 with SyndFeed

use of com.sun.syndication.feed.synd.SyndFeed in project rhsm-qe by RedHatQE.

the class EventTests method testProductDeleted.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6 }, testCaseID = { "RHEL6-26759" }, level = DefTypes.Level.COMPONENT, component = "subscription-manager", testtype = @TestType(testtype = DefTypes.TestTypes.FUNCTIONAL, subtype1 = DefTypes.Subtypes.RELIABILITY, subtype2 = DefTypes.Subtypes.EMPTY), posneg = PosNeg.POSITIVE, importance = DefTypes.Importance.HIGH, automation = DefTypes.Automation.AUTOMATED, tags = "Tier3")
@Test(description = "subscription-manager: events: Product Deleted is sent over an RSS atom feed.", groups = { "Tier3Tests", "ProductDeleted_Test" }, dependsOnGroups = { "PoolDeleted_Test" }, enabled = true, alwaysRun = true)
public // @ImplementsTCMS(id="")
void testProductDeleted() throws JSONException, IllegalArgumentException, IOException, FeedException {
    if (sm_serverAdminUsername.equals("") || sm_serverAdminPassword.equals(""))
        throw new SkipException("This test requires the candlepin server admin username and password credentials.");
    // WORKAROUND
    if (true)
        throw new SkipException("09/02/2010 Events for PRODUCT DELETED and the cpc delete_product are not yet dev complete.");
    // get the owner and consumer feeds before we test the firing of a new event
    SyndFeed oldFeed = CandlepinTasks.getSyndFeed(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl);
    // do something that will fire a delete product event
    // servertasks.cpc_delete_product(testProduct.getString("id"));
    String[] newEventTitles = new String[] { "PRODUCT DELETED" };
    // assert the feed...
    assertTheNewFeed(oldFeed, newEventTitles);
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SkipException(org.testng.SkipException) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 59 with SyndFeed

use of com.sun.syndication.feed.synd.SyndFeed in project rhsm-qe by RedHatQE.

the class EventTests method assertTheNewFeedIgnoringEventTitles.

protected void assertTheNewFeedIgnoringEventTitles(SyndFeed oldFeed, String[] newEventTitles, Set<String> ignoreEventTitles) throws IllegalArgumentException, IOException, FeedException {
    // assert the feed...
    SyndFeed newFeed = CandlepinTasks.getSyndFeed(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl);
    Assert.assertEquals(newFeed.getTitle(), "Event Feed");
    assertFeedContainsNoUnknownEvents(newFeed);
    log.info("Expecting the new feed to have grown by (" + newEventTitles.length + ") events:");
    int e = 0;
    for (String newEventTitle : newEventTitles) log.info(String.format("  Expecting entry[%d].title %s", e++, newEventTitle));
    int feedGrowthCount = getFeedGrowthCount(newFeed, oldFeed);
    Assert.assertTrue(feedGrowthCount >= newEventTitles.length, "At least " + newEventTitles.length + " new event feed entries has been pushed onto the stack (actual=" + feedGrowthCount + ").");
    int i = 0;
    for (String newEventTitle : newEventTitles) {
        String actualEventTitle = ((SyndEntryImpl) newFeed.getEntries().get(i)).getTitle();
        if (ignoreEventTitles.contains(actualEventTitle)) {
            log.warning("The next (" + i + ") newest event feed entry is '" + actualEventTitle + "', and will be ignored.");
        } else {
            Assert.assertEquals(actualEventTitle, newEventTitle, "The next (" + i + ") newest event feed entry is '" + newEventTitle + "'.");
        }
        i++;
    }
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SyndEntryImpl(com.sun.syndication.feed.synd.SyndEntryImpl)

Example 60 with SyndFeed

use of com.sun.syndication.feed.synd.SyndFeed in project rhsm-qe by RedHatQE.

the class EventTests method assertTheNewFeed.

/**
 * Same as assertTheNewFeed(SyndFeed oldFeed, String[] newEventTitles), but without regard to order of newEventTitles
 */
protected void assertTheNewFeed(SyndFeed oldFeed, List<String> newEventTitles) throws IllegalArgumentException, IOException, FeedException {
    // assert the feed...
    SyndFeed newFeed = CandlepinTasks.getSyndFeed(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl);
    Assert.assertEquals(newFeed.getTitle(), "Event Feed");
    assertFeedContainsNoUnknownEvents(newFeed);
    log.info("Expecting the new feed to have grown by the following " + newEventTitles.size() + " events (in no particular order): ");
    for (String newEventTitle : newEventTitles) log.info("    " + newEventTitle);
    // Assert.assertEquals(newFeed.getEntries().size(), oldFeed_EntriesSize+newEventTitles.size(), "The event feed entries has increased by "+newEventTitles.size());
    // if (oldFeed_EntriesSize+newEventTitles.size() <= feedLimit) {
    // Assert.assertEquals(newFeed.getEntries().size(), oldFeed_EntriesSize+newEventTitles.size(), "The event feed entries has increased by "+newEventTitles.size());
    // } else {
    // Assert.assertEquals(newFeed.getEntries().size(), feedLimit, "The event feed has hit the max entry count as set by the Candlepin class AtomResource/ConsumerResource/OwnerResource hard-coded variable feedlimit.");
    // }
    Assert.assertEquals(getFeedGrowthCount(newFeed, oldFeed), newEventTitles.size(), newEventTitles.size() + " new event feed entries has been pushed onto the stack.");
    List<String> newEventTitlesCloned = new ArrayList<String>();
    for (String newEventTitle : newEventTitles) newEventTitlesCloned.add(newEventTitle);
    for (int i = 0; i < newEventTitles.size(); i++) {
        String actualEventTitle = ((SyndEntryImpl) newFeed.getEntries().get(i)).getTitle();
        Assert.assertTrue(newEventTitlesCloned.remove(actualEventTitle), "The next (" + i + ") newest event feed entry (" + actualEventTitle + ") is among the expected list of event titles.");
    }
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SyndEntryImpl(com.sun.syndication.feed.synd.SyndEntryImpl) ArrayList(java.util.ArrayList)

Aggregations

SyndFeed (com.sun.syndication.feed.synd.SyndFeed)89 ArrayList (java.util.ArrayList)28 SyndEntry (com.sun.syndication.feed.synd.SyndEntry)25 TestDefinition (com.github.redhatqe.polarize.metadata.TestDefinition)16 ImplementsNitrateTest (com.redhat.qe.auto.tcms.ImplementsNitrateTest)16 SyndEntryImpl (com.sun.syndication.feed.synd.SyndEntryImpl)16 Test (org.testng.annotations.Test)16 Test (org.junit.Test)11 SkipException (org.testng.SkipException)11 BugzillaAPIException (com.redhat.qe.auto.bugzilla.BugzillaAPIException)10 SyndFeedImpl (com.sun.syndication.feed.synd.SyndFeedImpl)10 URL (java.net.URL)10 FeedException (com.sun.syndication.io.FeedException)9 SyndFeedInput (com.sun.syndication.io.SyndFeedInput)9 IOException (java.io.IOException)9 Date (java.util.Date)9 HashMap (java.util.HashMap)8 ConsumerCert (rhsm.data.ConsumerCert)8 XmlReader (com.sun.syndication.io.XmlReader)7 SyndFeedOutput (com.sun.syndication.io.SyndFeedOutput)6