func TestObjFindEventsByType(t *testing.T) {
	obj := models.NewIntellectualObject()

	// Add a creation event
	creationEvent := testutil.MakePremisEvent()
	creationEvent.EventType = constants.EventCreation
	obj.PremisEvents = append(obj.PremisEvents, creationEvent)

	// Add identifier assignment event
	idEvent := testutil.MakePremisEvent()
	idEvent.EventType = constants.EventIdentifierAssignment
	obj.PremisEvents = append(obj.PremisEvents, idEvent)

	// Add an ingest event
	ingestEvent := testutil.MakePremisEvent()
	ingestEvent.EventType = constants.EventIngestion
	obj.PremisEvents = append(obj.PremisEvents, ingestEvent)

	creationEvents := obj.FindEventsByType(constants.EventCreation)
	idEvents := obj.FindEventsByType(constants.EventIdentifierAssignment)
	ingestEvents := obj.FindEventsByType(constants.EventIngestion)

	require.Equal(t, 1, len(creationEvents))
	require.Equal(t, 1, len(idEvents))
	require.Equal(t, 1, len(ingestEvents))

	assert.Equal(t, creationEvent.Identifier, creationEvents[0].Identifier)
	assert.Equal(t, idEvent.Identifier, idEvents[0].Identifier)
	assert.Equal(t, ingestEvent.Identifier, ingestEvents[0].Identifier)
}
Example #2
0
func TestPremisEventMergeAttributes(t *testing.T) {
	event1 := testutil.MakePremisEvent()
	event2 := testutil.MakePremisEvent()

	err := event1.MergeAttributes(event2)
	require.Nil(t, err)
	assert.Equal(t, event1.Id, event2.Id)
	assert.Equal(t, event1.CreatedAt, event2.CreatedAt)
	assert.Equal(t, event1.UpdatedAt, event2.UpdatedAt)

	err = event1.MergeAttributes(nil)
	assert.NotNil(t, err)
}
Example #3
0
func TestPremisEventSave(t *testing.T) {
	testServer := httptest.NewServer(http.HandlerFunc(premisEventSaveHandler))
	defer testServer.Close()

	client, err := network.NewPharosClient(testServer.URL, "v2", "user", "key")
	if err != nil {
		t.Error(err)
		return
	}

	// ---------------------------------------------
	// Test create only. PremisEvents cannot be updaed
	// ---------------------------------------------
	obj := testutil.MakePremisEvent()
	obj.Id = 0
	response := client.PremisEventSave(obj)

	// Check the request URL and method
	assert.Equal(t, "POST", response.Request.Method)
	assert.Equal(t, "/api/v2/events/", response.Request.URL.Opaque)

	// Basic sanity check on response values
	assert.Nil(t, response.Error)

	obj = response.PremisEvent()
	assert.EqualValues(t, "PremisEvent", response.ObjectType())
	if obj == nil {
		t.Errorf("PremisEvent should not be nil")
	}
	assert.NotEqual(t, "", obj.Identifier)

	// Make sure the client returns the SAVED object,
	// not the unsaved one we sent.
	assert.NotEqual(t, 0, obj.Id)
}
Example #4
0
func premisEventGetHandler(w http.ResponseWriter, r *http.Request) {
	obj := testutil.MakePremisEvent()
	obj.Identifier = "000000000000-0000-0000-0000-00000000"
	objJson, _ := json.Marshal(obj)
	w.Header().Set("Content-Type", "application/json")
	fmt.Fprintln(w, string(objJson))
}
Example #5
0
func TestIsUrlAssignment(t *testing.T) {
	event := testutil.MakePremisEvent()
	event.EventType = constants.EventIdentifierAssignment
	event.Detail = "Assigned new storage URL blah blah blah THE INTERWEBZ!"
	assert.True(t, event.IsUrlAssignment())
	event.Detail = "What are you doing with that vat of sulfuric acid, Boris?"
	assert.False(t, event.IsUrlAssignment())
	event.EventType = constants.EventIngestion
	event.Detail = "Assigned new storage URL blah blah blah THE INTERWEBZ!"
	assert.False(t, event.IsUrlAssignment())
}
Example #6
0
func premisEventListHandler(w http.ResponseWriter, r *http.Request) {
	list := make([]*models.PremisEvent, 4)
	for i := 0; i < 4; i++ {
		list[i] = testutil.MakePremisEvent()
	}
	data := listResponseData()
	data["results"] = list
	listJson, _ := json.Marshal(data)
	w.Header().Set("Content-Type", "application/json")
	fmt.Fprintln(w, string(listJson))
}
Example #7
0
func TestMakePremisEvent(t *testing.T) {
	event := testutil.MakePremisEvent()
	if event == nil {
		t.Errorf("MakePremisEvent() returned nil")
		return
	}
	assert.NotEqual(t, 0, event.Id)
	assert.NotEqual(t, "", event.Identifier)
	assert.NotEqual(t, "", event.EventType)
	assert.False(t, event.DateTime.IsZero())
	assert.NotEqual(t, "", event.Detail)
	assert.NotEqual(t, "", event.Outcome)
	assert.NotEqual(t, "", event.OutcomeDetail)
	assert.NotEqual(t, "", event.Object)
	assert.NotEqual(t, "", event.Agent)
	assert.NotEqual(t, "", event.OutcomeInformation)
}
func TestNewPremisEventForPharos(t *testing.T) {
	event := testutil.MakePremisEvent()
	pharosEvent := models.NewPremisEventForPharos(event)
	assert.Equal(t, event.Id, pharosEvent.Id)
	assert.Equal(t, event.Identifier, pharosEvent.Identifier)
	assert.Equal(t, event.EventType, pharosEvent.EventType)
	assert.Equal(t, event.DateTime, pharosEvent.DateTime)
	assert.Equal(t, event.Detail, pharosEvent.Detail)
	assert.Equal(t, event.Outcome, pharosEvent.Outcome)
	assert.Equal(t, event.OutcomeDetail, pharosEvent.OutcomeDetail)
	assert.Equal(t, event.Object, pharosEvent.Object)
	assert.Equal(t, event.Agent, pharosEvent.Agent)
	assert.Equal(t, event.OutcomeInformation, pharosEvent.OutcomeInformation)
	assert.Equal(t, event.IntellectualObjectId, pharosEvent.IntellectualObjectId)
	assert.Equal(t, event.IntellectualObjectIdentifier, pharosEvent.IntellectualObjectIdentifier)
	assert.Equal(t, event.GenericFileId, pharosEvent.GenericFileId)
	assert.Equal(t, event.GenericFileIdentifier, pharosEvent.GenericFileIdentifier)
}