public void adjustMapForValues(Collection xAxisValues, Collection yAxisValues, int value) {
    // if one axis is null, we still need something to iterate over to get the other axis' values
    if (xAxisValues == null) {
      xAxisValues = EasyList.build((Object) null);
    }
    if (yAxisValues == null) {
      yAxisValues = EasyList.build((Object) null);
    }

    xAxisValues = transformAndRemoveInvaid(xAxisValues, xAxisMapper);
    yAxisValues = transformAndRemoveInvaid(yAxisValues, yAxisMapper);

    for (Object xvalue : xAxisValues) {
      addToXTotal(xvalue, value);
      for (Object yvalue : yAxisValues) {
        addValue(xvalue, yvalue, value);
      }
    }
    // We have to iterate over the y values alone so we don't mess up the totals
    for (Object yvalue : yAxisValues) {
      addToYTotal(yvalue, value);
    }

    // Always log one hit per unique issue.
    addToEntireTotal(value);
  }
  /** Make sure we can delete a search request that is in the cache. */
  @Test
  public void testDeleteInCache() {
    deletegateStore.getAllOwnedSearchRequests(adminUser);
    mockController.setReturnValue(EasyList.build(searchRequest1, searchRequest2));

    deletegateStore.delete(searchRequest2.getId());

    deletegateStore.getSearchRequest(searchRequest2.getId());
    mockController.setReturnValue(searchRequest2);

    mockController.replay();

    // prime the cache.
    cachingStore.getAllOwnedSearchRequests(adminUser);

    // execute the tests.
    cachingStore.delete(searchRequest2.getId());

    // these should be cached.
    assertEqualsNotSame(searchRequest1, cachingStore.getSearchRequest(searchRequest1.getId()));
    assertEqualsNotSame(
        EasyList.build(searchRequest1), cachingStore.getAllOwnedSearchRequests(adminUser));

    // this should not be cached.
    assertEqualsNotSame(searchRequest2, cachingStore.getSearchRequest(searchRequest2.getId()));

    mockController.verify();
  }
  @Test
  public void testHandleNotNodeAssocication() throws Exception {
    BackupProject backupProject =
        new BackupProjectImpl(
            new ExternalProject(),
            new ArrayList(),
            new ArrayList(),
            new ArrayList(),
            EasyList.build(new Long(12), new Long(14)));
    final SimpleProjectImportIdMapperImpl versionMapper = new SimpleProjectImportIdMapperImpl();
    IssueVersionMapperHandler issueVersionMapperHandler =
        new IssueVersionMapperHandler(backupProject, versionMapper);
    final Map attributes =
        EasyMap.build(
            "sourceNodeId",
            "10",
            "sourceNodeEntity",
            "Issue",
            "sinkNodeId",
            "20001",
            "sinkNodeEntity",
            "Version",
            "associationType",
            NodeAssociationParser.AFFECTS_VERSION_TYPE);

    issueVersionMapperHandler.handleEntity("NOT_NODE_ASSOCIATION", attributes);
    assertTrue(versionMapper.getRequiredOldIds().isEmpty());
  }
  @Test
  public void testParseException() {
    BackupProject backupProject =
        new BackupProjectImpl(
            new ExternalProject(),
            new ArrayList(),
            new ArrayList(),
            new ArrayList(),
            EasyList.build(new Long(12), new Long(14)));
    final SimpleProjectImportIdMapperImpl versionMapper = new SimpleProjectImportIdMapperImpl();
    IssueVersionMapperHandler issueVersionMapperHandler =
        new IssueVersionMapperHandler(backupProject, versionMapper);
    final Map attributes =
        EasyMap.build(
            "sourceNodeEntity",
            "Issue",
            "sinkNodeId",
            "20001",
            "sinkNodeEntity",
            "Version",
            "associationType",
            NodeAssociationParser.FIX_VERSION_TYPE);

    try {
      issueVersionMapperHandler.handleEntity(
          NodeAssociationParser.NODE_ASSOCIATION_ENTITY_NAME, attributes);
      fail("Should have thrown a parse exception");
    } catch (ParseException e) {
      // expected
    }
    assertTrue(versionMapper.getRequiredOldIds().isEmpty());
  }
  @Test
  public void testHandleAffectsVersion() throws Exception {
    BackupProject backupProject =
        new BackupProjectImpl(
            new ExternalProject(),
            new ArrayList(),
            new ArrayList(),
            new ArrayList(),
            EasyList.build(new Long(12), new Long(14)));
    final SimpleProjectImportIdMapperImpl versionMapper = new SimpleProjectImportIdMapperImpl();
    IssueVersionMapperHandler issueVersionMapperHandler =
        new IssueVersionMapperHandler(backupProject, versionMapper);
    final Map attributes =
        EasyMap.build(
            "sourceNodeId",
            "12",
            "sourceNodeEntity",
            "Issue",
            "sinkNodeId",
            "20001",
            "sinkNodeEntity",
            "Version",
            "associationType",
            NodeAssociationParser.AFFECTS_VERSION_TYPE);

    issueVersionMapperHandler.handleEntity(
        NodeAssociationParser.NODE_ASSOCIATION_ENTITY_NAME, attributes);
    assertEquals(1, versionMapper.getRequiredOldIds().size());
    assertEquals("20001", versionMapper.getRequiredOldIds().iterator().next());
  }
 public void testDoExecute() throws Exception {
   MockHttpServletResponse response =
       JiraTestUtil.setupExpectedRedirect("ViewFieldLayoutSchemes.jspa");
   Mock mockFieldLayoutShceme = new Mock(FieldLayoutScheme.class);
   mockFieldLayoutShceme.setStrict(true);
   String name = "some name";
   mockFieldLayoutShceme.expectVoid("setName", P.args(new IsEqual(name)));
   String description = "Test Description";
   mockFieldLayoutShceme.expectVoid("setDescription", P.args(new IsEqual(description)));
   mockFieldLayoutShceme.expectVoid("store");
   Long id = new Long(1);
   mockFieldLayoutShceme.expectAndReturn("getId", id);
   FieldLayoutScheme fieldLayoutScheme = (FieldLayoutScheme) mockFieldLayoutShceme.proxy();
   mockFieldLayoutManager.expectAndReturn(
       "getFieldLayoutSchemes", EasyList.build(fieldLayoutScheme));
   mockFieldLayoutManager.expectAndReturn(
       "getMutableFieldLayoutScheme", P.args(new IsEqual(id)), fieldLayoutScheme);
   efls.setFieldLayoutSchemeName(name);
   efls.setFieldLayoutSchemeDescription(description);
   efls.setId(id);
   assertEquals(Action.NONE, efls.execute());
   response.verify();
   mockFieldLayoutShceme.verify();
   mockFieldLayoutManager.verify();
 }
  /** Check that we can cache the owned search. */
  @Test
  public void testGetAllOwnedSearchRequest() {
    final List expectedRequests = EasyList.build(searchRequest1, searchRequest2, searchRequest3);

    deletegateStore.getSearchRequest(searchRequest1.getId());
    mockController.setReturnValue(searchRequest1);

    deletegateStore.getSearchRequest(searchRequest4.getId());
    mockController.setReturnValue(searchRequest4);

    deletegateStore.getAllOwnedSearchRequests(adminUser);
    mockController.setReturnValue(expectedRequests);

    mockController.replay();

    // put a value in the cache for the test.
    cachingStore.getSearchRequest(searchRequest1.getId());
    cachingStore.getSearchRequest(searchRequest4.getId());

    // this first call should not be cached and should delegate to getAllOwnedSearchRequests.
    assertEqualsNotSame(expectedRequests, cachingStore.getAllOwnedSearchRequests(adminUser));

    // these calls will now be cached.
    assertEqualsNotSame(expectedRequests, cachingStore.getAllOwnedSearchRequests(adminUser));
    assertEqualsNotSame(expectedRequests, cachingStore.getAllOwnedSearchRequests(adminUser));
    assertEqualsNotSame(expectedRequests, cachingStore.getAllOwnedSearchRequests(adminUser));

    // these should not also be cached.
    assertEqualsNotSame(searchRequest2, cachingStore.getSearchRequest(searchRequest2.getId()));
    assertEqualsNotSame(searchRequest3, cachingStore.getSearchRequest(searchRequest3.getId()));

    mockController.verify();
  }
Esempio n. 8
0
 public List getRecipients(IssueEvent event, String username) {
   User u = ManagerFactory.getUserManager().getUser(username);
   if (u != null) {
     return EasyList.build(new NotificationRecipient(u));
   }
   return Collections.EMPTY_LIST;
 }
  /**
   * Used to keep track of the irrelevant counts for the issues returned for this 2D stats map.
   *
   * @param xAxisValues null or the relevant X values for an issue
   * @param xIrrelevant true if the X field is not visible for the issue we are recording stats for,
   *     false otherwise
   * @param yAxisValues null or the relevant Y values for an issue
   * @param yIrrelevant true if the Y field is not visible for the issue we are recording stats for,
   *     false otherwise
   * @param incrementValue the value to increment the counts by, seems to always be 1, perhaps
   *     someone once thought we would do otherwise.
   */
  public void adjustMapForIrrelevantValues(
      final Collection xAxisValues,
      final boolean xIrrelevant,
      final Collection yAxisValues,
      final boolean yIrrelevant,
      final int incrementValue) {
    if (xIrrelevant && yIrrelevant) {
      // This is a irrelevant/irrelevant, all we need to do is keep track of the total amount of
      // these
      bothIrrelevant++;
    } else if (xIrrelevant && !yIrrelevant) {
      // Need to increment the TOTAL irrelevant count for X, we know there is only this one
      // Irrelevant value
      // This is to count UNIQUE issues and this is why we only count it once
      addToXTotal(FilterStatisticsValuesGenerator.IRRELEVANT, incrementValue);

      // Now we need to run through all the valid Y values and add an irrelevant total to the X
      // keyed against Y
      Collection transformedYValues;
      if (yAxisValues == null) {
        transformedYValues = EasyList.build((Object) null);
      } else {
        transformedYValues = transformAndRemoveInvaid(yAxisValues, yAxisMapper);
      }
      addToXIrrelevantTotals(transformedYValues, incrementValue);
    } else if (yIrrelevant && !xIrrelevant) {
      // Need to increment the TOTAL irrelevant count for Y, we know there is only this one
      // Irrelevant value
      // This is to count UNIQUE issues and this is why we only count it once
      addToYTotal(FilterStatisticsValuesGenerator.IRRELEVANT, incrementValue);

      // Now we need to run through all the valid X values and add an irrelevant total to the Y
      // keyed against X
      Collection transformedXValues;
      if (xAxisValues == null) {
        transformedXValues = EasyList.build((Object) null);
      } else {
        transformedXValues = transformAndRemoveInvaid(xAxisValues, xAxisMapper);
      }
      addToYIrrelevantTotals(transformedXValues, incrementValue);
    }

    // Always log one hit per unique issue.
    addToEntireTotal(1);
  }
  /** This should be a straight call through. */
  @Test
  public void testGetSearchRequestsGroup() {
    final EnclosedIterable expectedIterable =
        new MockCloseableIterable(EasyList.build(searchRequest4, searchRequest2));

    deletegateStore.getSearchRequests(group);
    mockController.setReturnValue(expectedIterable);
    mockController.replay();

    assertEquals(expectedIterable, cachingStore.getSearchRequests(group));

    mockController.verify();
  }
  /** Check what happens when try to save a search whose user has changed. */
  @Test
  public void testUpdateChangedUserName() {
    SearchRequest expectedRequest = new SearchRequest(searchRequest1);
    expectedRequest.setOwnerUserName(fredUser.getName());

    deletegateStore.getAllOwnedSearchRequests(adminUser);
    mockController.setReturnValue(EasyList.build(searchRequest1, searchRequest2, searchRequest3));

    deletegateStore.getAllOwnedSearchRequests(fredUser);
    mockController.setReturnValue(EasyList.build(searchRequest4));

    deletegateStore.update(expectedRequest);
    mockController.setReturnValue(expectedRequest);

    mockController.replay();

    // put a value in the cache for the test.
    cachingStore.getAllOwnedSearchRequests(adminUser);
    cachingStore.getAllOwnedSearchRequests(fredUser);

    // this call should work.
    assertEqualsNotSame(expectedRequest, cachingStore.update(expectedRequest));

    // all of these calls should be cache.
    assertEqualsNotSame(searchRequest2, cachingStore.getSearchRequest(searchRequest2.getId()));
    assertEqualsNotSame(searchRequest3, cachingStore.getSearchRequest(searchRequest3.getId()));
    assertEqualsNotSame(searchRequest4, cachingStore.getSearchRequest(searchRequest4.getId()));
    assertEqualsNotSame(expectedRequest, cachingStore.getSearchRequest(expectedRequest.getId()));

    assertEqualsNotSame(
        EasyList.build(searchRequest2, searchRequest3),
        cachingStore.getAllOwnedSearchRequests(adminUser));
    assertEqualsNotSame(
        EasyList.build(expectedRequest, searchRequest4),
        cachingStore.getAllOwnedSearchRequests(fredUser));

    mockController.verify();
  }
 public List<Attachment> getStoredAttachments(Issue issue) {
   try {
     GenericValue issueGV = issue.getGenericValue();
     Collection<GenericValue> attachmentGvs =
         issueGV.getRelatedOrderBy(
             "ChildFileAttachment", EasyList.build("filename ASC", "created DESC"));
     List<Attachment> attachments = new ArrayList<Attachment>(attachmentGvs.size());
     for (GenericValue attachmentGV : attachmentGvs) {
       attachments.add(
           new Attachment(
               issueManager, attachmentGV, OFBizPropertyUtils.getPropertySet(attachmentGV)));
     }
     return attachments;
   } catch (GenericEntityException e) {
     throw new DataAccessException(e);
   }
 }
  public void testAddErrorMessagesFromAResult() {
    ActionResult result = new ActionResult(Action.SUCCESS, null, null, null);

    JiraActionSupport jas = new JiraNonWebActionSupport();
    jas.addErrorMessages(result);

    assertEquals(0, jas.getErrorMessages().size());

    // now create a dummy action with an error message and check it gets added
    MockAction ma = new MockAction();
    ma.addErrorMessage("an error message");
    result = new ActionResult(Action.ERROR, null, EasyList.build(ma), null);
    jas.addErrorMessages(result);

    assertEquals(1, jas.getErrorMessages().size());
    assertEquals("an error message", jas.getErrorMessages().iterator().next());
  }
Esempio n. 14
0
  @Override
  public long getCountForCommentsRestrictedByGroup(String groupName) {
    if (groupName == null) {
      throw new IllegalArgumentException("You must provide a non null group name.");
    }

    EntityCondition condition =
        new EntityFieldMap(
            FieldMap.build("level", groupName, "type", ActionConstants.TYPE_COMMENT),
            EntityOperator.AND);
    List commentCount =
        delegator.findByCondition(
            "ActionCount", condition, EasyList.build("count"), Collections.EMPTY_LIST);
    if (commentCount != null && commentCount.size() == 1) {
      GenericValue commentCountGV = (GenericValue) commentCount.get(0);
      return commentCountGV.getLong("count").longValue();
    } else {
      throw new DataAccessException("Unable to access the count for the Action table");
    }
  }
 public void testDoValidationDuplicateName() throws Exception {
   Mock mockFieldLayoutShceme = new Mock(FieldLayoutScheme.class);
   mockFieldLayoutShceme.setStrict(true);
   String name = "some name";
   mockFieldLayoutShceme.expectAndReturn("getName", name);
   // Return a different id to cause an error
   mockFieldLayoutShceme.expectAndReturn("getId", new Long(2));
   Long id = new Long(1);
   FieldLayoutScheme fieldLayoutScheme = (FieldLayoutScheme) mockFieldLayoutShceme.proxy();
   mockFieldLayoutManager.expectAndReturn(
       "getFieldLayoutSchemes", EasyList.build(fieldLayoutScheme));
   efls.setFieldLayoutSchemeName(name);
   efls.setId(id);
   assertEquals(Action.INPUT, efls.execute());
   assertEquals(1, efls.getErrors().size());
   assertEquals(
       "A field configuration scheme with this name already exists.",
       efls.getErrors().get("fieldLayoutSchemeName"));
   mockFieldLayoutShceme.verify();
   mockFieldLayoutManager.verify();
 }
 @Test
 public void testNullSubTasksNonNullParentValues() {
   AggregateTimeTrackingCalculator calculator =
       new IssueImplAggregateTimeTrackingCalculator(
           new IssueImplAggregateTimeTrackingCalculator.PermissionChecker() {
             public boolean hasPermission(Issue subTask) {
               return true;
             }
           });
   AggregateTimeTrackingBean bean =
       calculator.getAggregates(
           getIssue(
               ZERO_ESTIMATE,
               ONE_ESTIMATE,
               BIG_ESTIMATE,
               EasyList.build(
                   getIssue(null, null, null, true),
                   getIssue(null, null, null, true),
                   getIssue(null, null, null, true))));
   assertNotNull(bean);
   assertEquals(ZERO_ESTIMATE, bean.getRemainingEstimate());
   assertEquals(ONE_ESTIMATE, bean.getOriginalEstimate());
   assertEquals(BIG_ESTIMATE, bean.getTimeSpent());
 }