package com.atlassian.bitbucket.internal.mirroring.mirror.rest;

import org.codehaus.jackson.map.ObjectMapper;
import org.junit.rules.ExternalResource;
import org.springframework.core.io.ClassPathResource;

import javax.annotation.Nonnull;
import java.util.Map;

import static com.google.common.base.Preconditions.checkNotNull;

public class MirrorJsonEntity extends ExternalResource {
    private static final ObjectMapper mapper = new ObjectMapper();

    private Map<String, Iterable<?>> json;
    private final String resourceName;

    public MirrorJsonEntity(@Nonnull String resourceName) {
        this.resourceName = checkNotNull(resourceName, "resourceName");
    }

    @SuppressWarnings("unchecked")
    @Override
    protected void before() throws Throwable {
        json = mapper.readValue(new ClassPathResource(resourceName).getInputStream(), Map.class);
    }

    public Map<String, ?> getValue() {
        return json;
    }
}
