Skip to content

Commit

Permalink
implement API find by name vim instance
Browse files Browse the repository at this point in the history
  • Loading branch information
marcellom committed Apr 25, 2019
1 parent 7e36594 commit c7b5818
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/datacenters")
Expand Down Expand Up @@ -171,6 +165,13 @@ public BaseVimInstance findById(
return vim;
}

@GetMapping(value = "search/findByName")
public BaseVimInstance findByName(
@RequestParam String name, @RequestHeader(value = "project-id") String projectId)
throws NotFoundException {
return vimManagement.queryByProjectIdAndName(projectId, name);
}

/**
* This operation updates the Network Service Descriptor (NSD)
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,15 @@
import static org.mockito.Mockito.when;

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.concurrent.ExecutionException;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.openbaton.catalogue.nfvo.viminstances.BaseVimInstance;
import org.openbaton.catalogue.nfvo.viminstances.OpenstackVimInstance;
import org.openbaton.exceptions.AlreadyExistingException;
import org.openbaton.exceptions.BadFormatException;
import org.openbaton.exceptions.BadRequestException;
import org.openbaton.exceptions.NotFoundException;
Expand All @@ -62,17 +56,15 @@ public void init() {
}

@Test
public void findAllVimInstances()
throws NoSuchAlgorithmException, InvalidKeyException, BadPaddingException,
NoSuchPaddingException, IllegalBlockSizeException, BadFormatException {
public void findAllVimInstances() throws BadFormatException {
when(mock.queryByProjectId("pi")).thenReturn(new ArrayList<>());
assertEquals(mock.queryByProjectId("pi"), restVimInstances.findAll("pi", "Bearer token"));
}

@Test
public void createVimInstance()
throws VimException, PluginException, IOException, BadRequestException,
AlreadyExistingException, ExecutionException, InterruptedException {
throws VimException, PluginException, IOException, BadRequestException, ExecutionException,
InterruptedException {
OpenstackVimInstance datacenter = new OpenstackVimInstance();
datacenter.setId("123");
datacenter.setName("DC-1");
Expand All @@ -89,9 +81,7 @@ public void createVimInstance()
}

@Test
public void findByIdVimInstance()
throws NoSuchAlgorithmException, InvalidKeyException, BadPaddingException,
NoSuchPaddingException, IllegalBlockSizeException, NotFoundException, BadFormatException {
public void findByIdVimInstance() throws NotFoundException, BadFormatException {
OpenstackVimInstance datacenter = new OpenstackVimInstance();
datacenter.setId("123");
datacenter.setName("DC-1");
Expand All @@ -101,10 +91,21 @@ public void findByIdVimInstance()
assertEquals(datacenter, restVimInstances.findById(datacenter.getId(), "pi", "Bearer token"));
}

@Test
public void findByNameVimInstance() throws NotFoundException {
OpenstackVimInstance datacenter = new OpenstackVimInstance();
datacenter.setId("123");
datacenter.setName("DC-1");
datacenter.setType("OpenStack");
datacenter.setName("datacenter_test");
when(mock.queryByProjectIdAndName(anyString(), anyString())).thenReturn(datacenter);
assertEquals(datacenter, restVimInstances.findByName(datacenter.getName(), "pi"));
}

@Test
public void updateVimInstance()
throws VimException, PluginException, IOException, BadRequestException,
AlreadyExistingException, NotFoundException, ExecutionException, InterruptedException {
throws VimException, PluginException, IOException, BadRequestException, NotFoundException,
ExecutionException, InterruptedException {
OpenstackVimInstance datacenter = new OpenstackVimInstance();
datacenter.setId("123");
datacenter.setName("DC-1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,14 @@ public BaseVimInstance query(String vimId) {
return vimRepository.findFirstById(vimId);
}

@Override
public BaseVimInstance queryByProjectIdAndName(String projectId, String name)
throws NotFoundException {
BaseVimInstance vim = vimRepository.findByProjectIdAndName(projectId, name);
if (vim == null) throw new NotFoundException("Not found vim Instance with name " + name);
return vim;
}

/**
* Validate if the Vim instance has all the required fields filled with values.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,6 @@ Future<Void> deleteNetwork(VirtualLinkRecord vlr)
throws PluginException, NotFoundException, VimException;

BaseVimInstance query(String vim_id);

BaseVimInstance queryByProjectIdAndName(String projectId, String name) throws NotFoundException;
}

0 comments on commit c7b5818

Please sign in to comment.