Package net.sf.collabreview.hooks

Source Code of net.sf.collabreview.hooks.HookTest

/*
   Copyright 2012 Christian Prause and Fraunhofer FIT

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

package net.sf.collabreview.hooks;

import net.sf.collabreview.core.ArtifactIdentifier;
import net.sf.collabreview.core.CollabReview;
import net.sf.collabreview.core.Repository;
import net.sf.collabreview.core.configuration.AutoConfigurator;
import net.sf.collabreview.core.users.Author;
import net.sf.collabreview.repository.Review;
import junit.framework.TestCase;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.util.Date;

/**
* Test if Hooks work...
*
* @author Christian Prause (chris)
* @date 2011-07-21 21:40
*/
public class HookTest extends TestCase {
  //private static final Log logger = LogFactory.getLog(HookTest.class);

  private static final ArtifactIdentifier aid1 = new ArtifactIdentifier("a", 1, "");

  private Author user1;

  private Repository repository;

  public void setUp() {
    CollabReview collabReview = AutoConfigurator.newConfiguredApplication();
    user1 = collabReview.getAuthorManager().createAuthor("abcyx");
    collabReview.getAuthorManager().storeAuthor(user1);
    repository = collabReview.getRepository();
    repository.addArtifact(aid1, new Date(), "some content", user1);
    repository.commit();
  }

  private class StateStore {
    int state = 0;
  }

  public void testSetReviewHook() {
    final StateStore stateStore = new StateStore();
    repository.registerSetReviewHook(new SetReviewHook() {
      @Override
      public int getPriority() {
        return PRIORITY_MEDIUM;
      }

      @Override
      public void reviewUpdated(Repository repository, Review oldReview, Review newReview) {
        stateStore.state = 1;
      }
    });
    assertEquals(0, stateStore.state);
    repository.setReview(aid1, user1, 10, "review", true);
    repository.commit();
    assertEquals(1, stateStore.state);
  }
}
TOP

Related Classes of net.sf.collabreview.hooks.HookTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.