// Path: allocate-service/src/test/java/com/stnetix/ariaddna/allocateservice/stub/VufsServiceStub.java
// public class VufsServiceStub implements IVufsService {
// 
//     @Override
//     public Metafile createEmptyMetafile() {
//         return null;
//     }
// 
//     @Override
//     public Metafile getMetafileByUuid(String fileUuid)
//             throws MetafileDoesNotExistException {
//         return null;
//     }
// 
//     @Override
//     public Metafile addBlockByUuidToMetafile(String blockUuid, Metafile metafile) {
//         return null;
//     }
// 
//     @Override
//     public Metafile removeBlockByUuidFromMetafile(String blockUuid, Metafile metafile) {
//         return null;
//     }
// 
//     @Override
//     public boolean addMetafileToMetatable(Metafile metafile) {
//         return false;
//     }
// 
//     @Override
//     public boolean removeMetafileFromMetatable(Metafile metafile) {
//         return false;
//     }
// 
//     @Override
//     public Set<String> getAllocationByBlockUuid(String blockUuid)
//             throws BlockNotExistInMetatableException {
//         Set<String> allocationSet = new HashSet<>();
//         for (int i = 0; i < 3; i++) {
//             allocationSet.add(UUID.randomUUID().toString());
//         }
//         return allocationSet;
//     }
// 
//     @Override
//     public void setAllocationForBlockByUuid(String blockUuid, Set<String> allocationSet) {
// 
//     }
// 
//     @Override
//     public boolean addMetafileAsChildToParent(Metafile childMetafile,
//             String parentMetafileUuid) {
//         return false;
//     }
// 
//     @Override
//     public boolean removeMetafileFromParent(String childMetafileUuid,
//             String parentMetafileUuid) {
//         return false;
//     }
// 
//     @Override
//     public AllocationStrategy getAllocationStrategyByMetafileUuid(String metafileUuid)
//             throws MetafileDoesNotExistException {
//         return AllocationStrategy.HA;
//     }
// 
//     @Override
//     public void setAllocationStrategyByMetafileUuid(String metafileUuid,
//             AllocationStrategy allocationStrategy) throws MetafileDoesNotExistException {
// 
//     }
// }
// 
// Path: common-utils/src/main/java/com/stnetix/ariaddna/commonutils/mavenutil/MavenUtil.java
// public class MavenUtil {
// 
//     private static final AriaddnaLogger LOGGER = AriaddnaLogger.getLogger(MavenUtil.class);
// 
//     private MavenUtil() {
//     }
// 
//     public static String getCurrentVersion() {
//         Model model = null;
//         try {
//             MavenXpp3Reader reader = new MavenXpp3Reader();
//             if ((new File("pom.xml")).exists()) {
//                 model = reader.read(new FileReader("pom.xml"));
//             } else {
//                 model = reader.read(new InputStreamReader(MavenUtil.class.getResourceAsStream(
//                         "/META-INF/maven/com.stnetix.ariaddna/common-utils/pom.xml")));
//             }
// 
//         } catch (IOException e) {
//             LOGGER.error("Can't read Pom.xml file. Exception message is: ", e.getMessage());
//         } catch (XmlPullParserException e) {
//             LOGGER.error("Can't parse Pom.xml file. Exception message is: ", e.getMessage());
//         }
//         return model != null ? model.getParent().getVersion() : "0.0.0";
//     }
// }


import com.stnetix.ariaddna.commonutils.mavenutil.MavenUtil;
import com.stnetix.ariaddna.rps.service.IResourcePolicyService;
import com.stnetix.ariaddna.vufs.bo.Block;
import com.stnetix.ariaddna.vufs.service.IVufsService;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.stnetix.ariaddna.allocateservice.exception.AllocateServiceException;
import com.stnetix.ariaddna.allocateservice.exception.AvailableSpaceNotExistException;
import com.stnetix.ariaddna.allocateservice.exception.BlockDoesNotExistInMetafileException;
import com.stnetix.ariaddna.allocateservice.service.AllocateServiceImpl;
import com.stnetix.ariaddna.allocateservice.stub.ResoucePolicyServiceStub;
import com.stnetix.ariaddna.allocateservice.stub.VufsServiceStub;
    public void getLocationForNewBlockThrowException()
            throws AvailableSpaceNotExistException, BlockDoesNotExistInMetafileException {
        Block block = getNewBlockBySize(6000000L);
        //here throw exception
        Set<String> newLocation = service.getLocationForNewBlock(block);

    }

    @Test
    public void getLocationForExistBlockByUuid() throws AllocateServiceException {
        Set<String> locations = service
                .getLocationForExistBlockByUuid(UUID.randomUUID().toString());
        assertNotNull(locations);
        assertEquals(3, locations.size());
    }

    @Test
    public void setLocationForBlock() throws BlockDoesNotExistInMetafileException {
        Set<String> allocationSet = new HashSet<>();
        for (int i = 0; i < 3; i++) {
            allocationSet.add(UUID.randomUUID().toString());
        }
        service.setLocationForBlock(allocationSet, UUID.randomUUID().toString());
    }

    private Block getNewBlockBySize(Long size) {
        byte[] payload = new byte[Math.toIntExact(size)];
        for (int i = 0; i < size; i++) {
            payload[i] = (byte) (i % 127);
        }
// Path: allocate-service/src/test/java/com/stnetix/ariaddna/allocateservice/stub/VufsServiceStub.java
// public class VufsServiceStub implements IVufsService {
// 
//     @Override
//     public Metafile createEmptyMetafile() {
//         return null;
//     }
// 
//     @Override
//     public Metafile getMetafileByUuid(String fileUuid)
//             throws MetafileDoesNotExistException {
//         return null;
//     }
// 
//     @Override
//     public Metafile addBlockByUuidToMetafile(String blockUuid, Metafile metafile) {
//         return null;
//     }
// 
//     @Override
//     public Metafile removeBlockByUuidFromMetafile(String blockUuid, Metafile metafile) {
//         return null;
//     }
// 
//     @Override
//     public boolean addMetafileToMetatable(Metafile metafile) {
//         return false;
//     }
// 
//     @Override
//     public boolean removeMetafileFromMetatable(Metafile metafile) {
//         return false;
//     }
// 
//     @Override
//     public Set<String> getAllocationByBlockUuid(String blockUuid)
//             throws BlockNotExistInMetatableException {
//         Set<String> allocationSet = new HashSet<>();
//         for (int i = 0; i < 3; i++) {
//             allocationSet.add(UUID.randomUUID().toString());
//         }
//         return allocationSet;
//     }
// 
//     @Override
//     public void setAllocationForBlockByUuid(String blockUuid, Set<String> allocationSet) {
// 
//     }
// 
//     @Override
//     public boolean addMetafileAsChildToParent(Metafile childMetafile,
//             String parentMetafileUuid) {
//         return false;
//     }
// 
//     @Override
//     public boolean removeMetafileFromParent(String childMetafileUuid,
//             String parentMetafileUuid) {
//         return false;
//     }
// 
//     @Override
//     public AllocationStrategy getAllocationStrategyByMetafileUuid(String metafileUuid)
//             throws MetafileDoesNotExistException {
//         return AllocationStrategy.HA;
//     }
// 
//     @Override
//     public void setAllocationStrategyByMetafileUuid(String metafileUuid,
//             AllocationStrategy allocationStrategy) throws MetafileDoesNotExistException {
// 
//     }
// }
// 
// Path: common-utils/src/main/java/com/stnetix/ariaddna/commonutils/mavenutil/MavenUtil.java
// public class MavenUtil {
// 
//     private static final AriaddnaLogger LOGGER = AriaddnaLogger.getLogger(MavenUtil.class);
// 
//     private MavenUtil() {
//     }
// 
//     public static String getCurrentVersion() {
//         Model model = null;
//         try {
//             MavenXpp3Reader reader = new MavenXpp3Reader();
//             if ((new File("pom.xml")).exists()) {
//                 model = reader.read(new FileReader("pom.xml"));
//             } else {
//                 model = reader.read(new InputStreamReader(MavenUtil.class.getResourceAsStream(
//                         "/META-INF/maven/com.stnetix.ariaddna/common-utils/pom.xml")));
//             }
// 
//         } catch (IOException e) {
//             LOGGER.error("Can't read Pom.xml file. Exception message is: ", e.getMessage());
//         } catch (XmlPullParserException e) {
//             LOGGER.error("Can't parse Pom.xml file. Exception message is: ", e.getMessage());
//         }
//         return model != null ? model.getParent().getVersion() : "0.0.0";
//     }
// }


// Path: allocate-service/src/test/java/com/stnetix/ariaddna/allocateservice/AllocateServiceImplTest.java
import com.stnetix.ariaddna.commonutils.mavenutil.MavenUtil;
import com.stnetix.ariaddna.rps.service.IResourcePolicyService;
import com.stnetix.ariaddna.vufs.bo.Block;
import com.stnetix.ariaddna.vufs.service.IVufsService;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.stnetix.ariaddna.allocateservice.exception.AllocateServiceException;
import com.stnetix.ariaddna.allocateservice.exception.AvailableSpaceNotExistException;
import com.stnetix.ariaddna.allocateservice.exception.BlockDoesNotExistInMetafileException;
import com.stnetix.ariaddna.allocateservice.service.AllocateServiceImpl;
import com.stnetix.ariaddna.allocateservice.stub.ResoucePolicyServiceStub;
import com.stnetix.ariaddna.allocateservice.stub.VufsServiceStub;

    public void getLocationForNewBlockThrowException()
            throws AvailableSpaceNotExistException, BlockDoesNotExistInMetafileException {
        Block block = getNewBlockBySize(6000000L);
        //here throw exception
        Set<String> newLocation = service.getLocationForNewBlock(block);

    }

    @Test
    public void getLocationForExistBlockByUuid() throws AllocateServiceException {
        Set<String> locations = service
                .getLocationForExistBlockByUuid(UUID.randomUUID().toString());
        assertNotNull(locations);
        assertEquals(3, locations.size());
    }

    @Test
    public void setLocationForBlock() throws BlockDoesNotExistInMetafileException {
        Set<String> allocationSet = new HashSet<>();
        for (int i = 0; i < 3; i++) {
            allocationSet.add(UUID.randomUUID().toString());
        }
        service.setLocationForBlock(allocationSet, UUID.randomUUID().toString());
    }

    private Block getNewBlockBySize(Long size) {
        byte[] payload = new byte[Math.toIntExact(size)];
        for (int i = 0; i < size; i++) {
            payload[i] = (byte) (i % 127);
        }
        return new Block(MavenUtil.getCurrentVersion(), 0L, UUID.randomUUID().toString(),