package com.braimatics.training.dao;

import com.braimatics.training.entity.Kelas;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;

@RunWith(SpringRunner.class)
@SpringBootTest
@Sql(
    scripts = {"/sampledata/clean.sql", "/sampledata/institusi.sql", "/sampledata/peserta.sql", "/sampledata/kelas.sql"}
)
public class KelasDaoTests {
    @Autowired private KelasDao kd;
    
    @Test
    @Transactional
    public void testCariKelasById(){
        Kelas k = kd.findOne("k001");
        Assert.assertNotNull(k);
        
        Assert.assertEquals("Kelas 001", k.getNama());
        Assert.assertTrue(2 == k.getDaftarMateri().size());
        Assert.assertTrue(5 == k.getDaftarPeserta().size());
    }
}

@@ -76,16 +76,211 @@
 .Kelas;%0A
+import com.braimatics.training.entity.Materi;%0Aimport com.braimatics.training.entity.Peserta;%0Aimport java.time.Instant;%0Aimport java.time.LocalTime;%0Aimport java.time.Period;%0Aimport java.util.Date;%0A
 import o
@@ -1225,10 +1225,1023 @@
 ;%0A    %7D%0A
+    %0A    @Test %0A    @Transactional%0A    public void testKelasBaru()%7B%0A        Kelas k = new Kelas();%0A        k.setKode(%22K-002%22);%0A        k.setNama(%22Kelas 002%22);%0A        k.setTanggalMulai(new Date());%0A        k.setTanggalSelesai(Date.from(Instant.now().plus(Period.ofDays(4))));%0A        %0A        kd.save(k);%0A        Assert.assertNotNull(k.getId());%0A        %0A        // menambah materi%0A        Materi m1 = new Materi();%0A        // idnya sudah tahu, langsung set aja gak perlu query dari db%0A        m1.setId(%22jfu001%22); %0A        k.getDaftarMateri().add(m1);%0A        %0A        Materi m2 = new Materi();%0A        m2.setId(%22jsi001%22);%0A        k.getDaftarMateri().add(m2);%0A        %0A        // tambah peserta%0A        Peserta p = new Peserta();%0A        p.setId(%22p001%22);%0A        k.getDaftarPeserta().add(p);%0A        %0A        kd.save(k);%0A        %0A        Kelas kx = kd.findOne(k.getId());%0A        Assert.assertTrue(2 == kx.getDaftarMateri().size());%0A        Assert.assertTrue(1 == kx.getDaftarPeserta().size());%0A           %0A    %7D%0A
 %7D%0A

test insert kelas baru