Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
rhbz1211849 - refactor and add functional test for slug change
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Huang committed May 13, 2015
1 parent bc694d4 commit 31b899d
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 20 deletions.
Expand Up @@ -63,6 +63,20 @@ public String getProjectId() {
return readyElement(projectIdField).getAttribute("value");
}

/**
* Enter a new slug for the project. Removes any existing text.
*
* @param projectSlug new project slug
* @return new Project General Settings page
*/
public ProjectGeneralTab enterProjectSlug(String projectSlug) {
log.info("Enter project slug {}", projectSlug);
waitForWebElement(projectIdField).clear();
waitForWebElement(projectIdField).sendKeys(projectSlug);
defocus(projectIdField);
return new ProjectGeneralTab(getDriver());
}

/**
* Enter a new name for the project. Removes any existing text.
*
Expand Down
Expand Up @@ -210,4 +210,24 @@ public void changeSourceLinks() throws Exception {
.isEqualTo("http://git.example.com")
.as("The git url is correct");
}

@Test
public void changeProjectSlug() {
ProjectGeneralTab projectGeneralTab = new ProjectWorkFlow()
.goToProjectByName("about fedora")
.gotoSettingsTab()
.gotoSettingsGeneral()
.enterProjectSlug("fedora-reborn")
.updateProject();

projectGeneralTab.reload();
// above will make sure url has been updated to use new slug
projectGeneralTab = projectGeneralTab
.gotoSettingsTab()
.gotoSettingsGeneral();

assertThat(projectGeneralTab.getProjectId())
.isEqualTo("fedora-reborn")
.as("The project slug is correct");
}
}
Expand Up @@ -18,6 +18,8 @@
import org.zanata.model.SlugEntityBase;
import org.zanata.service.IndexingService;
import org.zanata.util.Event;
import org.zanata.util.ServiceLocator;
import com.google.common.collect.Lists;

/**
* This class is a hibernate event listener which listens on post commit events
Expand All @@ -33,23 +35,9 @@
* @author Patrick Huang <a
* href="mailto:pahuang@redhat.com">pahuang@redhat.com</a>
*/
@Name("slugEntityUpdatedListener")
@Scope(ScopeType.APPLICATION)
@AutoCreate
@Slf4j
public class SlugEntityUpdatedListener implements PostUpdateEventListener {
private static final long serialVersionUID = -1L;
@In
private AsyncTaskHandleManager asyncTaskHandleManager;

@In
private IndexingService indexingServiceImpl;

@In("event")
private Event<ProjectUpdate> projectUpdateEvent;

@In("event")
private Event<ProjectIterationUpdate> projectIterationUpdateEvent;

private static Integer slugFieldIndexInProject;
private static Integer slugFieldIndexInIteration;
Expand All @@ -70,15 +58,15 @@ public void onPostUpdate(PostUpdateEvent event) {
slugFieldIndexInProject = getSlugFieldIndex(slugFieldIndexInProject, event);
String oldSlug = event.getOldState()[slugFieldIndexInProject].toString();
String newSlug = event.getState()[slugFieldIndexInProject].toString();
projectUpdateEvent.fire(new ProjectUpdate(project, oldSlug));
getProjectUpdateEvent().fire(new ProjectUpdate(project, oldSlug));
reindexIfProjectSlugHasChanged(oldSlug, newSlug, project);

} else if (slugEntityBase instanceof HProjectIteration) {
HProjectIteration iteration =
(HProjectIteration) slugEntityBase;
slugFieldIndexInIteration = getSlugFieldIndex(slugFieldIndexInIteration, event);
String oldSlug = event.getOldState()[slugFieldIndexInIteration].toString();
projectIterationUpdateEvent.fire(new ProjectIterationUpdate(
getProjectIterationUpdateEvent().fire(new ProjectIterationUpdate(
iteration, oldSlug));
}
}
Expand All @@ -89,9 +77,9 @@ public void reindexIfProjectSlugHasChanged(String oldSlug, String newSlug,
log.debug("HProject [{}] changed slug. old slug: {}, new slug: {}",
project, oldSlug, newSlug);
AsyncTaskHandle<Void> handle = new AsyncTaskHandle<>();
asyncTaskHandleManager.registerTaskHandle(handle);
getAsyncTaskHandleManager().registerTaskHandle(handle);
try {
indexingServiceImpl.reindexHTextFlowTargetsForProject(
getIndexingServiceImpl().reindexHTextFlowTargetsForProject(
project, handle);
} catch (Exception e) {
log.error("exception happen in async framework", e);
Expand Down Expand Up @@ -124,6 +112,25 @@ private static Integer getSlugFieldIndex(Integer slugFieldIndex, PostUpdateEvent
return i;
}
}
throw new IllegalStateException("can not find slug index in entity properties");
log.error("can not find slug index in entity [{}] properties [{}]",
event.getEntity(), Lists.newArrayList(propertyNames));
throw new IllegalStateException(
"can not find slug index in entity properties");
}

public AsyncTaskHandleManager getAsyncTaskHandleManager() {
return ServiceLocator.instance().getInstance(AsyncTaskHandleManager.class);
}

public IndexingService getIndexingServiceImpl() {
return ServiceLocator.instance().getInstance(IndexingService.class);
}

public Event<ProjectUpdate> getProjectUpdateEvent() {
return ServiceLocator.instance().getInstance("event", Event.class);
}

public Event<ProjectIterationUpdate> getProjectIterationUpdateEvent() {
return ServiceLocator.instance().getInstance("event", Event.class);
}
}
Expand Up @@ -39,7 +39,7 @@ public void integrate(Configuration configuration,
eventListenerRegistry.appendListeners(EventType.POST_INSERT,
updateListener);
eventListenerRegistry.appendListeners(EventType.POST_COMMIT_UPDATE,
ServiceLocator.instance().getInstance(SlugEntityUpdatedListener.class));
new SlugEntityUpdatedListener());
}
}

Expand Down

0 comments on commit 31b899d

Please sign in to comment.