Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
TungYuChiang committed Dec 26, 2024
1 parent ed54e77 commit 3849a98
Showing 1 changed file with 78 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import org.apache.gravitino.listener.api.info.TagInfo;
import org.apache.gravitino.tag.Tag;
import org.apache.gravitino.tag.TagChange;
import org.apache.gravitino.tag.TagDispatcher;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -75,6 +76,83 @@ void testListTagsEvent() {
Assertions.assertArrayEquals(tagNames, result);
}

@Test
void testAlterTagEvent() {
String metalake = "metalake";
String tagName = "testTag";
NameIdentifier identifier = NameIdentifier.of(metalake);
TagChange[] changes = new TagChange[] {TagChange.setProperty("key", "value")};

when(dispatcher.alterTag(metalake, tagName, changes)).thenReturn(tag);

Tag result = dispatcher.alterTag(metalake, tagName, changes);
Event event = dummyEventListener.popPostEvent();

Assertions.assertEquals(identifier, event.identifier());
Assertions.assertEquals(AlterTagEvent.class, event.getClass());
Assertions.assertEquals(tag.name(), ((AlterTagEvent) event).updatedTagInfo().name());
Assertions.assertEquals(tag.comment(), ((AlterTagEvent) event).updatedTagInfo().comment());
Assertions.assertEquals(tag.properties(), ((AlterTagEvent) event).updatedTagInfo().properties());
Assertions.assertEquals(OperationType.ALTER_TAG, event.operationType());
}


@Test
void testListTagsInfoEvent() {
String metalake = "metalake";
NameIdentifier identifier = NameIdentifier.of(metalake);
Tag[] tags = new Tag[] {tag, tag};

when(dispatcher.listTagsInfo(metalake)).thenReturn(tags);

Tag[] result = dispatcher.listTagsInfo(metalake);
Event event = dummyEventListener.popPostEvent();

Assertions.assertEquals(identifier, event.identifier());
Assertions.assertEquals(ListTagInfoEvent.class, event.getClass());
Assertions.assertEquals(OperationType.LISTINFO_TAG, event.operationType());
Assertions.assertArrayEquals(tags, result);
}

@Test
void testGetTagEvent() {
String metalake = "metalake";
String tagName = "testTag";
NameIdentifier identifier = NameIdentifier.of(metalake, tagName);

when(dispatcher.getTag(metalake, tagName)).thenReturn(tag);

Tag result = dispatcher.getTag(metalake, tagName);
Event event = dummyEventListener.popPostEvent();

Assertions.assertEquals(identifier, event.identifier());
Assertions.assertEquals(GetTagEvent.class, event.getClass());
Assertions.assertEquals(metalake, ((GetTagEvent) event).metalake());
Assertions.assertEquals(tagName, ((GetTagEvent) event).tagName());
Assertions.assertEquals(tag, ((GetTagEvent) event).tag());
Assertions.assertEquals(OperationType.GET_TAG, event.operationType());
}

@Test
void testDeleteTagEvent() {
String metalake = "metalake";
String tagName = "testTag";
NameIdentifier identifier = NameIdentifier.of(metalake, tagName);

when(dispatcher.deleteTag(metalake, tagName)).thenReturn(true);

boolean result = dispatcher.deleteTag(metalake, tagName);
Event event = dummyEventListener.popPostEvent();

Assertions.assertEquals(identifier, event.identifier());
Assertions.assertEquals(DeleteTagEvent.class, event.getClass());
Assertions.assertTrue(((DeleteTagEvent) event).isExists());
Assertions.assertEquals(OperationType.DELETE_TAG, event.operationType());
Assertions.assertTrue(result);
}





private Tag mockTag() {
Expand Down

0 comments on commit 3849a98

Please sign in to comment.